This API endpoint translates an existing message to another language. The source language is inferred from the user language or detected automatically by analyzing its text. If possible it is recommended to store the user language, see " Set user language " section later in this page.
// Translate message to Frenchval channelClient = client.channel("messaging", "general")val message = Message(text = "Hello, I would like to have more information about your product.")channelClient.sendMessage(message).enqueue { result -> if (result is Result.Success) { val messageId = result.value.id val frenchLanguage = "fr" client.translate(messageId, frenchLanguage).enqueue { translationResult -> if (translationResult is Result.Success) { val translatedMessage: Message = translationResult.value val translation = translatedMessage.getTranslation(frenchLanguage) } else { // Handle Result.Failure } } } else { // Handle Result.Failure }}
let messageController = chatClient.messageController(cid: <#T##ChannelId#>, messageId: <#T##MessageId#>)messageController.translate(to: .french) { error in if error == nil { print(messageController.message?.translations?[.french]) }}
await channel.sendMessage(Message( id: messageId, text: 'Hello, I would like to have more information about your product.',));// returns the message.text translated into Frenchfinal response = await channel.translateMessage(messageId, 'fr');// the translation will be added to the i18n objectprint(response.message.i18n['fr_text']);// "Bonjour, J'aimerais avoir plus d'informations sur votre produit.",
await channel.sendMessage({ id: messageID, text: "Hello, I would like to have more information about your product.",});// returns the message.text translated into Frenchconst response = await client.translateMessage(messageID, "fr");// the translation will be added to the i18n objectconsole.log(response.message.i18n.fr_text);// "Bonjour, J'aimerais avoir plus d'informations sur votre produit.",
// Not yet supported in the Unreal SDK
$response = $client->translateMessage($msgId, new Models\TranslateMessageRequest(language: "hu"));echo $response->getData()->message->i18n["fr_text"];
var resp = await chat.TranslateMessageAsync(message.Id, new TranslateMessageRequest{ Language = "fr",});resp.Message.I18n["fr_text"];
// Will be implemented soon, raise a GitHub issue if you need this feature https://github.com/GetStream/stream-chat-unity/issues/
// Android SDK// Translate message to FrenchChannelClient channelClient = client.channel("messaging", "general");Message message = new Message();message.setText("Hello, I would like to have more information about your product.");channelClient.sendMessage(message).enqueue(result -> { if (result.isSuccess()) { String messageId = result.data().getId(); client.translate(messageId, "fr").enqueue(translationResult -> { if (translationResult.isSuccess()) { Message translatedMessage = translationResult.data(); String translation = translatedMessage.getI18n().get("fr_text"); } else { // Handle translationResult.error() } }); } else { // Handle result.error() } });// Backend SDKvar messageRequest = MessageRequest.builder() .id(messageId) .text("Hello, I would like to have more information about your product.") .userID(userId) .build();chat.channel(channelType, channelId) .sendMessage(SendMessageRequest.builder().message(messageRequest).build());// returns the message.text translated into Frenchvar response = chat.translateMessage(messageId, TranslateMessageRequest.builder().language("fr").build()) .execute();System.out.println(response.getData().getMessage().getI18n().get("fr_text"));// "Bonjour, J'aimerais avoir plus d'informations sur votre produit."
The endpoint returns the translated message, updates it and sends a message.updated event to all users on the channel.
Only the text field is translated, custom fields and attachments are not included.
When a message is translated, the i18n object is added. The i18n includes the message text in all languages and the code of the original language.
The i18n object has one field for each language named using this convention language-code_text
Here is an example after translating a message from english into French and Italian.
{ "fr_text": "Bonjour, J'aimerais avoir plus d'informations sur votre produit.", "it_text": "Ciao, vorrei avere maggiori informazioni sul tuo prodotto.", "language": "en"}
Automatic translation translates all messages immediately when they are added to a channel and are delivered to the other users with the translated text directly included.
Automatic translation works really well for 1-1 conversations or group channels with two main languages.
Let's see how this works in practice:
A user sends a message and automatic translation is enabled
The language set for that user is used as source language (if not the source language will be automatically detected)
The message text is translated into the other language in used on the channel by its members
When using auto translation, it is recommended setting the language for all users and add them as channel members
Automatic translation is not enabled by default. You can enable it for your application via API or CLI from your backend. You can also enable auto translation on a channel basis.
// enable auto-translation only for this channelawait channel.update({ auto_translation_enabled: true });// ensure all messages are translated in english for this channelawait channel.update({ auto_translation_enabled: true, auto_translation_language: "en",});// auto translate messages for all channelsawait client.updateAppSettings({ auto_translation_enabled: true });
// Backend SDK// enable auto-translation only for this channelchat.channel("channeltype", "channelid") .update(UpdateChannelRequest.builder() .data(ChannelInputRequest.builder().autoTranslationEnabled(true).build()) .build());// ensure all messages are translated in english for this channelchat.channel("channeltype", "channelid") .update(UpdateChannelRequest.builder() .data(ChannelInputRequest.builder() .autoTranslationEnabled(true) .autoTranslationLanguage("en") .build()) .build());// auto translate messages for all channelsclient.updateApp(UpdateAppRequest.builder().autoTranslationEnabled(true).build()).execute();
// enable auto-translation only for this channel$client->updateChannel("messaging", "general", new Models\UpdateChannelRequest( data: new Models\ChannelInputRequest(autoTranslationEnabled: true),));// ensure all messages are translated in english for this channel$client->updateChannel("messaging", "general", new Models\UpdateChannelRequest( data: new Models\ChannelInputRequest( autoTranslationEnabled: true, autoTranslationLanguage: "en", ),));// auto translate messages for all channels$client->updateApp(new Models\UpdateAppRequest(autoTranslationEnabled: true));
from getstream.models import ChannelInputRequest# enable auto-translation only for this channelchannel.update(data=ChannelInputRequest(auto_translation_enabled=True))# ensure all messages are translated in english for this channelchannel.update(data=ChannelInputRequest(auto_translation_enabled=True, auto_translation_language="en"))# auto translate messages for all channelsclient.update_app(auto_translation_enabled=True)
require 'getstream_ruby'Models = GetStream::Generated::Models# enable auto-translation only for this channelclient.chat.update_channel('messaging', channel_id, Models::UpdateChannelRequest.new( data: Models::ChannelInputRequest.new(auto_translation_enabled: true)))# ensure all messages are translated in english for this channelclient.chat.update_channel('messaging', channel_id, Models::UpdateChannelRequest.new( data: Models::ChannelInputRequest.new( auto_translation_enabled: true, auto_translation_language: 'en' )))# auto translate messages for all channelsclient.common.update_app(Models::UpdateAppRequest.new(auto_translation_enabled: true))
channel := client.Chat().Channel("messaging", "channel-id")// enable auto-translation only for this channelchannel.Update(ctx, &getstream.UpdateChannelRequest{ Data: &getstream.ChannelInputRequest{ AutoTranslationEnabled: getstream.PtrTo(true), },})// ensure all messages are translated in english for this channelchannel.Update(ctx, &getstream.UpdateChannelRequest{ Data: &getstream.ChannelInputRequest{ AutoTranslationEnabled: getstream.PtrTo(true), AutoTranslationLanguage: getstream.PtrTo("en"), },})// auto translate messages for all channelsclient.UpdateApp(ctx, &getstream.UpdateAppRequest{ AutoTranslationEnabled: getstream.PtrTo(true),})
// enable auto-translation only for this channelawait chat.UpdateChannelAsync(channel.Type, channel.Id, new UpdateChannelRequest{ Data = new ChannelInput { AutoTranslationEnabled = true },});// ensure all messages are translated in english for this channelawait chat.UpdateChannelAsync(channel.Type, channel.Id, new UpdateChannelRequest{ Data = new ChannelInput { AutoTranslationEnabled = true, AutoTranslationLanguage = "en" },});// auto translate messages for all channelsawait client.UpdateAppAsync(new UpdateAppRequest { AutoTranslationEnabled = true });
// Will be implemented soon, raise a GitHub issue if you need this feature https://github.com/GetStream/stream-chat-unity/issues/
In order for auto translation to work, you must set the user language or specify a destination language for the channel using the auto_translation_language field (see previous code example).
// Sets the user languageclient.connectUser(user = User(id = "userId", language = "en"), token = "userToken").await()
// Backend SDK// sets the user languageawait client.connectUser({ id: "userId", language: "en" }, userToken);// watch a channelawait client.channel("messaging", "melting-pot");
// Backend SDK// sets the user languageclient.updateUsers(UpdateUsersRequest.builder() .users(Map.of("userId", UserRequest.builder().id("userId").language("en").build())) .build()).execute();
// sets the user language$client->updateUsers(new Models\UpdateUsersRequest( users: ["userid" => new Models\UserRequest(id: "userid", language: "en")],));
from getstream.models import UserRequest# sets the user languageclient.upsert_users(UserRequest(id="userId", language="en"))
require 'getstream_ruby'Models = GetStream::Generated::Models# sets the user languageclient.common.update_users(Models::UpdateUsersRequest.new( users: { 'userId' => Models::UserRequest.new(id: 'userId', language: 'en') }))
// sets the user languageclient.UpdateUsers(ctx, &getstream.UpdateUsersRequest{ Users: map[string]getstream.UserRequest{ "userId": { ID: "userId", Language: getstream.PtrTo("en"), }, },})
// sets the user languageawait client.UpsertUsersAsync(new UpdateUsersRequest{ Users = new Dictionary<string, UserRequest> { { user.Id, new UserRequest { Id = user.Id, Language = "en" } }, },});
// Will be implemented soon, raise a GitHub issue if you need this feature https://github.com/GetStream/stream-chat-unity/issues/
// Sets the user languageChatClient.shared.connectUser( userInfo: UserInfo(id: "userId", language: .english), token: userToken)
Messages are automatically translated from the user language that posts the message to the most common language in use by the other channel members.
Translation is only done for messages with up to 5,000 characters. Blowin' In The Wind from Bob Dylan contains less than 1,000 characters
Error messages and commands are not translated (ie. /giphy hello)
When a message is updated, translations are recomputed automatically
Changing translation settings or user language have no effect on messages that are already translated
If there are three or more languages being used by channel members, auto-translate will default to the most common language used by the channel members. Therefore, this feature is best suited for groups with a maximum of two main languages.
A workaround to support more than two languages is to use the translateMessage endpoint to store translated messages for multiple languages, and render the appropriate translation depending on the current users language.