Skip to content

Commit ccca1da

Browse files
committed
feat(LanguageTranslator): add support for language detection
1 parent cd3a592 commit ccca1da

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

Scripts/Services/LanguageTranslator/V3/LanguageTranslatorService.cs

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,19 @@ public LanguageTranslatorService(string versionDate, Authenticator authenticator
9191
/// <summary>
9292
/// Translate.
9393
///
94-
/// Translates the input text from the source language to the target language.
94+
/// Translates the input text from the source language to the target language. A target language or translation
95+
/// model ID is required. The service attempts to detect the language of the source text if it is not specified.
9596
/// </summary>
9697
/// <param name="callback">The callback function that is invoked when the operation completes.</param>
9798
/// <param name="text">Input text in UTF-8 encoding. Multiple entries will result in multiple translations in
9899
/// the response.</param>
99-
/// <param name="modelId">A globally unique string that identifies the underlying model that is used for
100-
/// translation. (optional)</param>
101-
/// <param name="source">Translation source language code. (optional)</param>
102-
/// <param name="target">Translation target language code. (optional)</param>
100+
/// <param name="modelId">The model to use for translation. For example, `en-de` selects the IBM provided base
101+
/// model for English to German translation. A model ID overrides the source and target parameters and is
102+
/// required if you use a custom model. If no model ID is specified, you must specify a target language.
103+
/// (optional)</param>
104+
/// <param name="source">Language code that specifies the language of the source document. (optional)</param>
105+
/// <param name="target">Language code that specifies the target language for translation. Required if model ID
106+
/// is not specified. (optional)</param>
103107
/// <returns><see cref="TranslationResult" />TranslationResult</returns>
104108
public bool Translate(Callback<TranslationResult> callback, List<string> text, string modelId = null, string source = null, string target = null)
105109
{
@@ -716,15 +720,18 @@ private void OnListDocumentsResponse(RESTConnector.Request req, RESTConnector.Re
716720
/// <param name="file">The contents of the source file to translate.
717721
///
718722
/// [Supported file
719-
/// types](https://cloud.ibm.com/docs/services/language-translator?topic=language-translator-document-translator-tutorial#supported-file-formats)
723+
/// types](https://cloud.ibm.com/docs/language-translator?topic=language-translator-document-translator-tutorial#supported-file-formats)
720724
///
721725
/// Maximum file size: **20 MB**.</param>
722726
/// <param name="filename">The filename for file.</param>
723727
/// <param name="fileContentType">The content type of file. (optional)</param>
724-
/// <param name="modelId">The model to use for translation. `model_id` or both `source` and `target` are
725-
/// required. (optional)</param>
728+
/// <param name="modelId">The model to use for translation. For example, `en-de` selects the IBM provided base
729+
/// model for English to German translation. A model ID overrides the source and target parameters and is
730+
/// required if you use a custom model. If no model ID is specified, you must specify a target language.
731+
/// (optional)</param>
726732
/// <param name="source">Language code that specifies the language of the source document. (optional)</param>
727-
/// <param name="target">Language code that specifies the target language for translation. (optional)</param>
733+
/// <param name="target">Language code that specifies the target language for translation. Required if model ID
734+
/// is not specified. (optional)</param>
728735
/// <param name="documentId">To use a previously submitted document as the source for a new translation, enter
729736
/// the `document_id` of the document. (optional)</param>
730737
/// <returns><see cref="DocumentStatus" />DocumentStatus</returns>
@@ -1015,4 +1022,4 @@ private void OnGetTranslatedDocumentResponse(RESTConnector.Request req, RESTConn
10151022
((RequestObject<byte[]>)req).Callback(response, resp.Error);
10161023
}
10171024
}
1018-
}
1025+
}

Scripts/Services/LanguageTranslator/V3/Model/DocumentStatus.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ public class StatusValue
7979
[JsonProperty("source", NullValueHandling = NullValueHandling.Ignore)]
8080
public string Source { get; set; }
8181
/// <summary>
82+
/// A score between 0 and 1 indicating the confidence of source language detection. A higher value indicates
83+
/// greater confidence. This is returned only when the service automatically detects the source language.
84+
/// </summary>
85+
[JsonProperty("detected_language_confidence", NullValueHandling = NullValueHandling.Ignore)]
86+
public double? DetectedLanguageConfidence { get; set; }
87+
/// <summary>
8288
/// Translation target language code.
8389
/// </summary>
8490
[JsonProperty("target", NullValueHandling = NullValueHandling.Ignore)]

Scripts/Services/LanguageTranslator/V3/Model/TranslationResult.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ public class TranslationResult
3636
[JsonProperty("character_count", NullValueHandling = NullValueHandling.Ignore)]
3737
public long? CharacterCount { get; set; }
3838
/// <summary>
39+
/// The language code of the source text if the source language was automatically detected.
40+
/// </summary>
41+
[JsonProperty("detected_language", NullValueHandling = NullValueHandling.Ignore)]
42+
public string DetectedLanguage { get; set; }
43+
/// <summary>
44+
/// A score between 0 and 1 indicating the confidence of source language detection. A higher value indicates
45+
/// greater confidence. This is returned only when the service automatically detects the source language.
46+
/// </summary>
47+
[JsonProperty("detected_language_confidence", NullValueHandling = NullValueHandling.Ignore)]
48+
public double? DetectedLanguageConfidence { get; set; }
49+
/// <summary>
3950
/// List of translation output in UTF-8, corresponding to the input text entries.
4051
/// </summary>
4152
[JsonProperty("translations", NullValueHandling = NullValueHandling.Ignore)]

0 commit comments

Comments
 (0)