translate_message_text()¶
- Client.translate_message_text()¶
Translates a text or message(s) to the given language. If the current user is a Telegram Premium user, then text formatting is preserved.
- Parameters:¶
to_language_code (
str
) – Language code of the language to which the message/text is translated. Must be one of the supported language codes.chat_id (
Optional[int | str]
) – Unique identifier (int) or username (str) of the target chat.message_ids (
Optional[int | List[int]]
) – Identifier or list of message identifiers of the target message(s).text (
Optional[str]
) – Text to translate.parse_mode (
ParseMode
, optional) – By default, texts are parsed using both Markdown and HTML styles. You can combine both syntaxes together.entities (List of
MessageEntity
) – List of special entities that appear in message text, which can be specified instead of parse_mode.
Example
# Using chat_id and message_ids await app.translate_message_text("en", chat_id, message_ids) # Using text await app.translate_message_text("en", text="Hello, how are you?") # Using text with parse_mode await app.translate_message_text("en", text="*Hello*, how are you?", parse_mode=ParseMode.MARKDOWN) # Using text with entities entities = [types.MessageEntityBold(offset=0, length=5)] await app.translate_message_text("en", text="*Hello*, how are you?", entities=entities)
- Returns:¶
TranslatedText
| List ofTranslatedText
– In case message_ids was not a list, a single result is returned, otherwise a list of results is returned.