translateMessage method

Future<ChatMessage> translateMessage({
  1. required ChatMessage msg,
  2. required List<String> languages,
})

~english Translates a text message.

Param msg The message object for translation.

Param languages The list of target language codes.

Return The translated message.

Throws A description of the exception. See ChatError. ~end

~chinese 翻译一条文本消息。

Param msg 要翻译的文本消息。

Param languages 目标语言代码列表。

Return 译文。

Throws 如果有异常会在此抛出,包括错误码和错误信息,详见 ChatError。 ~end

Implementation

Future<ChatMessage> translateMessage({
  required ChatMessage msg,
  required List<String> languages,
}) async {
  Map req = {};
  req["message"] = msg.toJson();
  req["languages"] = languages;
  Map result =
      await ChatChannel.invokeMethod(ChatMethodKeys.translateMessage, req);
  try {
    ChatError.hasErrorFromResult(result);
    return ChatMessage.fromJson(result[ChatMethodKeys.translateMessage]);
  } on ChatError catch (e) {
    throw e;
  }
}