Skip to main content
The Message Translation extension helps you translate messages into multiple languages.

Extension settings

  1. Login to CometChat and select your app.
  2. Go to the Extensions section and enable 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: 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

The 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.
The result will be received in the success callback of the callExtension() method. It will have the following JSON structure:
If the source language is not supported for translation, then you will get the following error:

Translating at the sender’s end

If the languages of the end-users/receivers are known before hand, this method of implementation can be used. That is, before your trigger CometChat.sendMessage method, make a call to the message translation extension as mentioned above. Since the message has not been sent yet, the msgId won’t be available and can be skipped in that call. Once you get the response, make an entry in your message’s metadata as shown below:
Then, at the receiver’s end, based on the device/browser language, you can show the translated text message in their chats from the metadata.

Translating at the receiver’s end

If the languages of the end-users/receivers are not known before hand, this method of implementation can be used. Simply show a translate button above every message bubble in the UI. Make a call to the extension as mentioned above. The translation can then be shown in the same message bubble. However, unlike the translations that are saved in the metadata when translating at the sender’s end, these translations are ephemeral and will be lost once the page is reloaded, the user fetches older messages and scrolls back to the latest translated messages or the user switces conversations and comes back to the conversation with translated messages.