tencent cloud



Last updated: 2024-03-13 17:23:03


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.
This feature is available only in SDK enhanced edition v7.0 or later.
You need to submit a ticket to contact us to activate it.

Translating Text Messages

Call the translateText API (Android / iOS & macOS / Windows) to translate texts.
API parameters are described as follows:
Input Parameter
List of text messages to be translated
1. Multiple text messages can be passed in at a time.
2. UTF-8 encoding is required; otherwise, translation will failed.
3. For non-pure texts such as those with HTML tags, the translation may fail.
4. The total texts to be translated per request can contain up to 2,000 characters (each Chinese character, letter, punctuation mark, or space is counted as a character).
Source language
Pass in a specific language or auto (automatically identify the source language). If no value is passed in, the default value auto will be used.
Target language
Multiple target languages are supported. For more information, see Supported Text Translation Languages.
Translation result callback
In the callback, key indicates the text to be translated, and value indicates the translated text.
Sample code:
iOS and macOS
List<String> textList = new ArrayList<>();
String targetLanguage = "en";
V2TIMManager.getMessageManager().translateText(textList, null, targetLanguage, new V2TIMValueCallback<HashMap<String, String>>() {
public void onSuccess(HashMap<String, String> translateHashMap) {
// Texts translated successfully. `translateHashMap`: {"": "Good morning", "": "Good afternoon", "": "Good evening"}

public void onError(int code, String desc) {
// Text translation failed
NSArray *sourceText = @[@"", @"", @""];
NSString *targetLanguage = @"en";
[[V2TIMManager sharedInstance] translateText:sourceText
completion:^(int code, NSString *desc, NSDictionary<NSString *,NSString *> *result) {
if (code == 0) {
// Texts translated successfully. `result`: @{@"": @"Good morning", @"": @"Good afternoon", @"": @"Good evening"}
} else {
// Text translation failed
template <class T>
class ValueCallback final : public V2TIMValueCallback<T> {
using SuccessCallback = std::function<void(const T&)>;
using ErrorCallback = std::function<void(int, const V2TIMString&)>;

ValueCallback() = default;
~ValueCallback() override = default;

void SetCallback(SuccessCallback success_callback, ErrorCallback error_callback) {
success_callback_ = std::move(success_callback);
error_callback_ = std::move(error_callback);

void OnSuccess(const T& value) override {
if (success_callback_) {
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);

SuccessCallback success_callback_;
ErrorCallback error_callback_;

V2TIMStringVector textList;
V2TIMString targetLanguage = u8"en";

auto callback = new ValueCallback<V2TIMStringToV2TIMStringMap>{};
[=](const V2TIMStringToV2TIMStringMap& result) {
// Texts translated successfully. `result`: {{"", "Good morning"}, {"", "Good afternoon"}, {"", "Good evening"}}
delete callback;
[=](int error_code, const V2TIMString& error_message) {
// Text translation failed
delete callback;

V2TIMManager::GetInstance()->GetMessageManager()->TranslateText(textList, "", targetLanguage, callback);

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)
th (Thai)
zh (Simplified Chinese), en (English)
ms (Malay)
zh (Simplified Chinese), en (English)
ar (Arabic)
en (English)
hi (Hindi)
en (English)

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 avaliable.

7x24 Phone Support