Check user language

Babel is required.

check_user_language.py
 1"""
 2Babel is required.
 3"""
 4
 5import logging
 6
 7from aiogram import Bot, Dispatcher, executor, md, types
 8
 9API_TOKEN = 'BOT TOKEN HERE'
10
11logging.basicConfig(level=logging.INFO)
12
13
14bot = Bot(token=API_TOKEN, parse_mode=types.ParseMode.MARKDOWN)
15dp = Dispatcher(bot)
16
17
18@dp.message_handler()
19async def check_language(message: types.Message):
20    locale = message.from_user.locale
21
22    await message.reply(md.text(
23        md.bold('Info about your language:'),
24        md.text('🔸', md.bold('Code:'), md.code(locale.language)),
25        md.text('🔸', md.bold('Territory:'), md.code(locale.territory or 'Unknown')),
26        md.text('🔸', md.bold('Language name:'), md.code(locale.language_name)),
27        md.text('🔸', md.bold('English language name:'), md.code(locale.english_name)),
28        sep='\n',
29    ))
30
31
32if __name__ == '__main__':
33    executor.start_polling(dp, skip_updates=True)