mirror of
https://github.com/aiogram/aiogram.git
synced 2026-04-08 16:37:47 +00:00
i18n: normalize Telegram region codes in locale detection
Resolve user locale by checking the Telegram language code as-is, then its Babel-normalized form, then the base language. This fixes lowercase regional codes such as pt-br failing to match available translations like pt_BR. Add tests covering region-code variants and fallback behavior, and update i18n documentation plus changelog notes.
This commit is contained in:
parent
73710acb4c
commit
53ad537739
4 changed files with 55 additions and 4 deletions
|
|
@ -113,6 +113,16 @@ On top of your application the instance of :class:`aiogram.utils.i18n.I18n` shou
|
|||
|
||||
After that you will need to choose one of builtin I18n middleware or write your own.
|
||||
|
||||
When using :class:`aiogram.utils.i18n.middleware.SimpleI18nMiddleware`, locale codes from
|
||||
Telegram (for example ``pt-br``) are resolved against loaded locales in two steps:
|
||||
|
||||
1. Direct match as received from Telegram (``pt-br``)
|
||||
2. Normalized Babel-style identifier (``pt_BR``)
|
||||
|
||||
So if your translations are stored under
|
||||
``locales/pt_BR/LC_MESSAGES/messages.mo``, they will be selected for users with
|
||||
``language_code="pt-br"``.
|
||||
|
||||
Builtin middlewares:
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue