Translation
Feature Description
The message translation feature currently supports the translation of text messages only, which can be triggered by manual API calls. Non-text messages such as image, video, file, audio, and custom messages cannot be translated.
Note:
Text translation is a value-added paid feature. You can contact us through the Telegram Technical Support Group to enable you to use the full feature.
Display Effect
translateText
Translating Text Messages
API
chat.translateText(options);
Parameter
The
options
parameter is of the Object
type. It contains the following attribute values:Name | Type | Description |
sourceTextList | Array<String> | List of texts to be translated. |
sourceLanguage | String | Source Language. 'auto' indicates the SDK automatically identifies the source language. |
targetLanguage | String | Target Language. For example: English - 'en' Simplified Chinese - 'zh' French - 'fr' German - 'de' |
Returned Value
Promise
Sample
// Translate Arabic to Chineselet promise = chat.translateText({sourceTextList: ['مرحبًا'],sourceLanguage: 'auto',targetLanguage: 'en'});promise.then(function(imResponse) {const { translatedTextList } = imResponse.data;}).catch(function(imError) {// error code 2117 indicates translation failedconsole.warn('translateText error:', imError);});
// Translate English to Chineselet promise = chat.translateText({sourceTextList: ['Hello Tencent', 'Build in-app chat with Tencent Cloud Chat'],sourceLanguage: 'auto',targetLanguage: 'zh'});promise.then(function(imResponse) {const { translatedTextList } = imResponse.data;}).catch(function(imError) {// error code 2117 indicates translation failedconsole.warn('translateText error:', imError);});
Supported Text Translation Languages
Source Language | Supported Target Language |
zh (Simplified Chinese) | en (English), ja (Japanese), ko (Korean), fr (French), es (Spanish), it (Italian), de (German), tr (Turkish), ru (Russian), pt (Portuguese), vi (Vietnamese), id (Bahasa Indonesian), th (Thai), and ms (Malay) |
zh-TW (Traditional Chinese) | en (English), ja (Japanese), ko (Korean), fr (French), es (Spanish), it (Italian), de (German), tr (Turkish), ru (Russian), pt (Portuguese), vi (Vietnamese), id (Bahasa Indonesian), th (Thai), and ms (Malay) |
en (English) | zh (Simplified Chinese), ja (Japanese), ko (Korean), fr (French), es (Spanish), it (Italian), de (German), tr (Turkish), ru (Russian), pt (Portuguese), vi (Vietnamese), id (Bahasa Indonesian), th (Thai), ms (Malay), ar (Arabic), and hi (Hindi) |
ja (Japanese) | zh (Simplified Chinese), en (English), ko (Korean) |
ko (Korean) | zh (Simplified Chinese), en (English), ja (Japanese) |
fr (French) | zh (Simplified Chinese), en (English), es (Spanish), it (Italian), de (German), tr (Turkish), ru (Russian), and pt (Portuguese) |
es (Spanish) | zh (Simplified Chinese), en (English), fr (French), it (Italian), de (German), tr (Turkish), ru (Russian), and pt (Portuguese) |
it (Italian) | zh (Simplified Chinese), en (English), fr (French), es (Spanish), de (German), tr (Turkish), ru (Russian), and pt (Portuguese) |
de (German) | zh (Simplified Chinese), en (English), fr (French), es (Spanish), it (Italian), tr (Turkish), ru (Russian), and pt (Portuguese) |
tr (Turkish) | zh (Simplified Chinese), en (English), fr (French), es (Spanish), it (Italian), de (German), ru (Russian), and pt (Portuguese) |
ru (Russian) | zh (Simplified Chinese), en (English), fr (French), es (Spanish), it (Italian), de (German), tr (Turkish), and pt (Portuguese) |
pt (Portuguese) | zh (Simplified Chinese), en (English), fr (French), es (Spanish), it (Italian), de (German), tr (Turkish), and ru (Russian) |
vi (Vietnamese) | zh (Simplified Chinese), en (English) |
id (Bahasa Indonesian) | zh (Simplified Chinese), en (English) |