Skip to content

Custom language code function

sushka edited this page Aug 12, 2023 · 1 revision

You may need to define custom function to extract language code from user.

Here's how you can do it:

async def force_ukrainian_language(user: User, bot: Bot) -> str:
    force_list = [733876760]
    if user.id in force_list:
        return "uk"  # Set force ukrainian language for account with 733876760 id
    else:
        return user.language_code

translator = Translator(extract_language_function=force_ukrainian_language)

This function must have 2 arguments with types User and Bot and return str.