Exemple #1
0
        private string GetEffectiveModelName(TranslationModel?model)
        {
            var effectiveModel = model ?? DefaultModel;

            TranslationModels.ValidateModel(effectiveModel);
            return(effectiveModel.ToApiName());
        }
Exemple #2
0
        private void ModifyRequest(ListRequest request, string sourceLanguage, FormatEnum format, TranslationModel?model)
        {
            request.ModifyRequest += _versionHeaderAction;
            request.Source         = sourceLanguage;
            request.Format         = format;
            var effectiveModel = model ?? DefaultModel;

            TranslationModels.ValidateModel(effectiveModel);
            request.Model = effectiveModel.ToApiName();
        }
Exemple #3
0
 /// <summary>
 /// Constructs a new client wrapping the given <see cref="TranslateService"/>.
 /// </summary>
 /// <param name="service">The service to wrap. Must not be null.</param>
 /// <param name="model">The default translation model to use. Defaults to <see cref="TranslationModel.ServiceDefault"/>.</param>
 public TranslationClientImpl(TranslateService service, TranslationModel model = TranslationModel.ServiceDefault)
 {
     Service = GaxPreconditions.CheckNotNull(service, nameof(service));
     TranslationModels.ValidateModel(model);
     DefaultModel = model;
 }
 /// <summary>
 /// Constructs an instance from an API result.
 /// </summary>
 internal TranslationResult(TranslationsResource resource, string originalText, string specifiedSourceLanguage, string targetLanguage)
     : this(originalText, resource.TranslatedText, resource.DetectedSourceLanguage,
            specifiedSourceLanguage, targetLanguage, TranslationModels.GetModel(resource.Model))
 {
 }
 /// <summary>
 /// Constructs an instance.
 /// </summary>
 /// <remarks>This constructor is for the benefit of testability, in case you wish to provide your own
 /// fake implementation of <see cref="TranslationClient"/>.</remarks>
 /// <param name="originalText">The original text.</param>
 /// <param name="translatedText">The translated text.</param>
 /// <param name="detectedSourceLanguage">The source language code detected by the server, if any.</param>
 /// <param name="specifiedSourceLanguage">The source language code specified by the API caller.</param>
 /// <param name="targetLanguage">The target language code.</param>
 /// <param name="model">The model used to perform the translation, if known.</param>
 public TranslationResult(string originalText, string translatedText, string detectedSourceLanguage, string specifiedSourceLanguage,
                          string targetLanguage, TranslationModel?model) : this(originalText, translatedText, detectedSourceLanguage, specifiedSourceLanguage,
                                                                                targetLanguage, model, model == null ? null : TranslationModels.ToApiName(model.Value))
 {
 }