please select
  • UIKit
  • SDK
  • Server APIs
Chat/
SDK/
Android/
Message/
SDK
  • Install Chat SDK
  • Initialize Chat SDK
  • Login and Logout
  • Message
    • Overview
    • Send a Message
    • Receive a Message
    • Retrieve Messages
    • Forward Messages
    • Modify a Message
    • Insert a Message
    • Delete Messages
    • Clear History Messages
    • Recall a Message
    • Send an Online Message
    • Message Read Receipt
    • Query Messages
    • Mentions
    • Targeted Group Message
    • Do not Notify
    • Key-Value Extensions
    • Reactions
    • Translation
    • Pin Messages
  • Conversation
    • Overview
    • Conversation List
    • Get Conversations
    • Unread Count
    • Pin Conversations
    • Delete Conversations
    • Draft
    • Mark
    • Conversation Group
  • Group
    • Overview
    • Manage Group
    • Profile
    • Manage Members
    • Member Profile
    • Attribute
    • Counter
  • Community and Topic
    • Manage Community
    • Permission Group
  • User
    • User Profile
    • User Status
    • Manage Friends
    • Friend Group
    • Block Lists
    • Follow
  • Local Search
    • Search Messages
    • Search Friends
    • Search Groups
    • Search Group Members
  • Signaling
  • API Reference
    • Java
  • Guideline for Beginners
  • Console Guide
    • Creating and Upgrading an Application
    • Basic Configuration
    • Feature Configuration
    • Account Management
    • Group Management
    • Webhook Configuration
  • Product Introduction
    • Message Management
      • One-to-One Message
      • Message Storage
      • Offline Push
      • Group Message
      • Message Formats
    • Account System
      • Login Authentication
      • Online Status Management
    • Group Related
      • Group System
      • Group Management
    • User Profile and Relationship Chain
      • Profile Management
      • Relationship Chain Management
  • Purchase Guide
    • Billing Overview
    • Pricing
  • Error Codes

Translation

Overview

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, which is still in the beta phase. You can contact us through the Telegram Technical Support Group to enable you to experience the full feature.
This feature is available only in SDK enhanced edition v7.0 or later.

Effect

You can use the Message Translation feature to implement the translation effect shown in the diagram below:



Note:
You can also directly use the UI-inclusive Translation Plugin, TUITranslationPlugin, to quickly obtain translation capabilities.

Interface Description

Translating Text Messages

Call the translateText API (Android / iOS & macOS / Windows) to translate texts.
API parameters are described as follows:
Input Parameter
Definition
Description
sourceTextList
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).
sourceLanguage
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.
targetLanguage
Target language
Multiple target languages are supported. For more information, see Supported Text Translation Languages.
callback
Translation result callback
In the callback, key indicates the text to be translated, and value indicates the translated text.
Sample code:
Android
iOS and macOS
Windows
List<String> textList = new ArrayList<>();
textList.add("");
textList.add("");
textList.add("");
String targetLanguage = "en";
V2TIMManager.getMessageManager().translateText(textList, null, targetLanguage, new V2TIMValueCallback<HashMap<String, String>>() {
@Override
public void onSuccess(HashMap<String, String> translateHashMap) {
// Texts translated successfully. `translateHashMap`: {"": "Good morning", "": "Good afternoon", "": "Good evening"}
}

@Override
public void onError(int code, String desc) {
// Text translation failed
}
});
NSArray *sourceText = @[@"", @"", @""];
NSString *targetLanguage = @"en";
[[V2TIMManager sharedInstance] translateText:sourceText
sourceLanguage:nil
targetLanguage:targetLanguage
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> {
public:
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_) {
success_callback_(value);
}
}
void OnError(int error_code, const V2TIMString& error_message) override {
if (error_callback_) {
error_callback_(error_code, error_message);
}
}

private:
SuccessCallback success_callback_;
ErrorCallback error_callback_;
};

V2TIMStringVector textList;
textList.PushBack(u8"");
textList.PushBack(u8"");
textList.PushBack(u8"");
V2TIMString targetLanguage = u8"en";

auto callback = new ValueCallback<V2TIMStringToV2TIMStringMap>{};
callback->SetCallback(
[=](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)