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:
mahisafa82 2026-02-26 03:07:37 +03:30
parent 73710acb4c
commit 53ad537739
No known key found for this signature in database
4 changed files with 55 additions and 4 deletions

View file

@ -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: