messages.translateText #

Translate a given text.

Styled text entities will only be preserved for Telegram Premium users.

Layer 223

messages.translateResult#33db32f8 result:Vector<TextWithEntities> = messages.TranslatedText;
---functions---
messages.translateText#63183030 flags:# peer:flags.0?InputPeer id:flags.0?Vector<int> text:flags.1?Vector<TextWithEntities> to_lang:string = messages.TranslatedText;

Parameters #

NameTypeDescription
flags#Flags, see TL conditional fields
peerflags.0?InputPeerIf the text is a chat message, the peer ID
idflags.0?Vector<int>A list of message IDs to translate
textflags.1?Vector<TextWithEntities>A list of styled messages to translate
to_langstringTwo-letter ISO 639-1 language code of the language to which the message is translated
toneflags.2?stringIf set, rephrases the translation using the specified AI composer tone » (pass the tone identifier)

Result #

messages.TranslatedText

Only users can use this method #

Possible errors #

CodeTypeDescription
400INPUT_TEXT_EMPTYThe specified text is empty.
400INPUT_TEXT_TOO_LONGThe specified text is too long.
400MSG_ID_INVALIDInvalid message ID provided.
400PEER_ID_INVALIDThe provided peer id is invalid.
400TO_LANG_INVALIDThe specified destination language is invalid.
500TRANSLATE_REQ_FAILEDTranslation failed, please try again later.
400TRANSLATE_REQ_QUOTA_EXCEEDEDTranslation is currently unavailable due to a temporary server-side lack of resources.
406TRANSLATIONS_DISABLEDTranslations are unavailable, a detailed and localized description for the error will be emitted via an updateServiceNotification as specified here ».
500TRANSLATION_TIMEOUTA timeout occurred while translating the specified text.

AI features #

Telegram offers many AI features powered by Cocoon — a decentralized network designed to maximize privacy.

Styled text with message entities #

How to create styled text with message entities

Telegram Premium #

Telegram Premium is an optional subscription service that unlocks additional exclusive client-side and API-side features, while helping support the development of the app.

Error handling #

How to handle API return errors correctly.