Message Translation

Learn how to translate messages on-the-fly.

The Message Translation extension helps you translate messages into multiple languages.

Settings

  1. Login to the CometChat Dashboard
  2. On the Extensions page add the Message Translation extension.

How does it work?

The messages translation extension allows the receivers of the message to translate it in the language of their choice.
In a group of multi-lingual people, a message sent by one of the participants can be in English. However, it can be translated by other members of the group to their languages.

We support translations in the following languages:

Afrikaans (af) Albanian (sq) Amharic (am) Arabic (ar) Armenian (hy) Azerbaijani (az)
Bengali (bn) Bosnian (bs) Bulgarian (bg) Catalan (ca) Chinese (Simplified) (zh) Chinese (Traditional) (zh-TW)
Croatian (hr) Czech (cs) Danish (da) Dari (fa-AF) Dutch (nl) English (en)
Estonian (et) Farsi (Persian) (fa) Filipino Tagalog (tl) Finnish (fi) French (fr) French (Canada) (fr-CA)
Georgian (ka) German (de) Greek (el) Gujarati (gu) Haitian Creole (ht) Hausa (ha)
Hebrew (he) Hindi (hi) Hungarian (hu) Icelandic (is) Indonesian (id) Italian (it)
Japanese (ja) Kannada (kn) Kazakh (kk) Korean (ko) Latvian (lv) Lithuanian (lt)
Macedonian (mk) Malay (ms) Malayalam (ml) Maltese (mt) Mongolian (mn) Norwegian (no)
Persian (fa) Pashto (ps) Polish (pl) Portuguese (pt) Romanian (ro) Russian (ru)
Serbian (sr) Sinhala (si) Slovak (sk) Slovenian (sl) Somali (so) Spanish (es)
Spanish (Mexico) (es-MX) Swahili (sw) Swedish (sv) Tagalog (tl) Tamil (ta) Telugu (te)
Thai (th) Turkish (tr) Ukrainian (uk) Urdu (ur) Uzbek (uz) Vietnamese (vi)
Welsh (cy)

The language is identified using identifiers from RFC 5646 — if there is a 2-letter ISO 639-1 identifier, with a regional subtag if necessary, it uses that. Otherwise, it uses the ISO 639-2 3-letter code.

Implementation

Once the extension has been enabled from the dashboard. You can start using it for translating the messages at the receiver's end.
This extension uses the callExtension() method provided by CometChat SDKs.

The messages will be translated according to the languages specified by the receiver. You can specify the languages for translation as an array. If you pass in an empty array, the language will default to English.

CometChat.callExtension('message-translation', 'POST', 'v2/translate', {
  "msgId": 12,
  "text": "Hey there! How are you?",
  "languages": [ "ru", "hi", "mr" ]
}).then( result => {
    // Result of translations
})
.catch(error => {
  // Some error occured
});
import org.json.simple.JSONObject;

JSONObject body=new JSONObject();
JSONArray languages = new JSONArray();

languages.add("ru");
languages.add("hi");

body.put("msgId", 12);
body.put("languages", languages);
body.put("text", "Hey there! How are you?");

CometChat.callExtension("message-translation", "POST", "/v2/translate", body,
 new CometChat.CallbackListener < JSONObject > () {
    @Override
    public void onSuccess(JSONObject jsonObject) {
        // Result of translations
    }
    @Override
    public void onError(CometChatException e) {
        // Some error occured
    }
});
CometChat.callExtension(slug: "message-translation", type: .post, endPoint: "v2/translate", body: ["msgId": 12 ,"languages": ["hi", "ru"], "text": "Hey there! How are you?"] as [String : Any], onSuccess: { (response) in
         // Result of translations
      }) { (error) in
         // Some error occured
      }

The result will be received in the success callback of the callExtension() method. It will have the following JSON structure:

{
  "msgId": 12,
  "translations": [
    {
      "message_translated": "Эй там! Как ты?",
      "language_translated": "ru",
      "error": null,
      "error_description": null
    },
    {
      "message_translated": "अरे वहाँ! आप कैसे हैं?",
      "language_translated": "hi",
      "error": null,
      "error_description": null
    },
    {
      "message_translated": "",
      "language_translated": "mr",
      "error": "UnsupportedLanguagePairException",
      "error_description": "Unsupported language pair: en to mr. Target language 'mr' is not supported"
    }
  ],
    "language_original": "en"
}

If the source language is not supported for translation, then you will get the following error:

{
  "code": "ERR_NOT_SUPPORTED",
  "message": "Autodetected source language '<language_code>' is not supported"
}

Did this page help you?