TranslatorLibrary.TranslateAsync(string, string, string, string) Method
The TranslateAsync(string, string, string, string) method translates a text from one language to another language.
Published date: October 21, 2013
public IAsyncAction TranslateAsync(string languageFrom, string languageTo, string category, string textToTranslate)
languageFrom
Type: System.String
Optional. A string representing the language code of the translation text. If left empty the response will include the result of language auto-detection.
languageTo
Type: System.String
Required. A string representing the language code to translate the text into.
category
Type: System.String
Optional. A string containing the category (domain) of the translation. Defaults to "general".
textToTranslate
Type: System.String
Required. A string representing the text to translate. The size of the text must not exceed 10000 characters.
Type: Bing.Translator.TranslationResult
The translated text and the Result Code.
If you previously used the AddTranslation or AddTranslationArray methods through the public Translator API to enter a translation with a rating of 5 or higher for the same source sentence, Translate returns only the top choice that is available to your system. The "same source sentence" means the exact same (100% matching), except for capitalization, white space, tag values, and punctuation at the end of a sentence. If no rating is stored with a rating of 5 or above, then the returned result will be the automatic translation by Microsoft Translator.
Example
The following example retrieves the languages codes that the TranslatorControl can translate form and to.
var result = await this.Translator2.TranslatorApi.TranslateAsync("en", "es", "", "Translate this text.");
Example
The following example translates the specified text from the default language into Spanish, and writes the result to a UI element.
// Initialize a TranslatorLibrary instance. var translatorApi = Bing.Translator.TranslatorLibrary("CLIENTID", "CLIENTSECRET"); // Get the translated text and write it to a UI element with an ID of 'translation'. translatorApi.translateAsync("", "es", "", "This is a Bing Translator Control JavaScript sample").then(function (result) { document.getElementById('translation').innerText = result.textTranslated; });
Requirements
Minimum Supported Client | Windows 8.1 |
Required Extensions | Bing Translator Control |
Namespace |