H
H
haoiwi2022-04-02 17:12:16
Python
haoiwi, 2022-04-02 17:12:16

Python, multilanguage, telebot?

I am writing a telegram bot in Python, through the telebot library, how can I make it multilingual (without inline clave), there are no normal guides .....

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2022-04-02
@SoreMix

Create a dictionary that has a key in the form of some kind of phrase designation, say start_message. Its value is two dictionaries, one with the key RU, the other EN, or whatever. Initially, you ask the user what language is needed, save his choice. In the future, when receiving a message from the user, select the appropriate element from the dictionary

messages = {'start_message': {'ru': 'Привет', 'en': 'Hello'}}


@bot.message_handler()
def start_message(message):
    bot.send_message(message.chat.id, messages['start_message'][user_locale])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question