CometChat Pro Documentation

You'll find comprehensive guides and documentation to help you start working with CometChat as quickly as possible. Let's jump right in!

Message Translation

Learn how to translate messages on-the-fly.

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

To translate a message to multiple languages, while sending the message, you need to specify the languages you would like to translate the message to.

We support translation between the following 25 languages: Arabic, Chinese (Simplified), Chinese (Traditional), Czech, Danish, Dutch, English, Finnish, French, German, Hebrew, Hindi, Indonesian, Italian, Japanese, Korean, Malay, Norwegian, Persian, Polish, Portuguese, Russian, Spanish, Swedish, and Turkish.

We identify the language 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.

	"message_translation_languages": [ "en", "hi", "..." ]

You can programmatically set this as follows-

var receiverID = "UID";
var messageText = "Hello World!";
var receiverType = CometChat.RECEIVER_TYPE.USER;

var textMessage = new CometChat.TextMessage(receiverID, messageText, receiverType);

var metadata = {
    "message_translation_languages": ["en","hi","ru"]


    message => {
        console.log("Message sent successfully:", message);
    error => {
        console.log("Message sending failed with error:", error);

At the recipients' end, the message will automatically include the translated languages. Here is a sample response:

"@injected": {
    "extensions": {
      "message-translation": {
        "translations": [
            "message_translated": "हैलो दुनिया",
            "language_translated": "hi"
            "message_translated": "привет мир",
            "language_translated": "ru"
        "language_original": "en"

At the recipients' end, from the message object, you can fetch the metadata by calling the getMetadata() method. Using this metadata, you can fetch translated messages.

var metadata = message.getMetadata();
if (metadata != null) {
    var injectedObject = metadata["@injected"];
    if (injectedObject != null && injectedObject.hasOwnProperty("extensions")) {
        var extensionsObject = injectedObject["extensions"];
        if (extensionsObject != null && extensionsObject.hasOwnProperty("message-translation")) {
            var messageTranslationObject = extensionsObject["message-translation"];
            var translations = messageTranslationObject["translations"];
            var translationsMap = {};
            for (var i = 0; i < Object.keys(translations).length; i++) {
                var translation = translations[i];
                var translatedText = translation["message_translated"];
                var translatedLanguage = translation["language_translated"];
                translationsMap[translatedLanguage] = translatedText;

The translationsMap contains all the translated messages as values and the language codes as the keys.

Message Translation

Learn how to translate messages on-the-fly.

Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.