SDKsHarmonyOSEnterprise
Translate message
Translate a synchronized message and obtain an updated message object containing translated content.
Locates the target message using conversationID and clientMsgID.
Code example
import sdk, { TranslateMessageReq, TranslateMessageResp } from '@openimsdk/imsdk';
const request: TranslateMessageReq = {
conversationID: conversationID,
clientMsgID: message.clientMsgID,
sourceLanguageCode: 'en',
targetLanguageCode: 'zh-CN',
};
const response: TranslateMessageResp = await sdk.translateMessage(request);
replaceMessage(response.message.clientMsgID, response.message);Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
conversationID | string | Yes | Target conversation identifier. |
clientMsgID | string | Yes | Client message identifier of the message to translate. |
sourceLanguageCode | string | Yes | Source language code (for example, 'en'). |
targetLanguageCode | string | Yes | Target language code (for example, 'zh-CN'). |
Return value
Returns a Promise resolving to TranslateMessageResp:
| Property | Type | Description |
|---|---|---|
message | IMMessage | Updated message object containing translated text. |
State changes after the call
The source message must already be synchronized to the local database. After the Promise resolves, update the local message item matching conversationID:clientMsgID, while preserving the original message text for toggle display. This operation does not broadcast translation results to other client devices. For standalone text translation, see Translate text.
Was this page helpful?