FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

i18n: add source_locale parameter to I18n by mahisafa82 · Pull Request #1817 · aiogram/aiogram · GitHub

i18n: add source_locale parameter to I18n - #1817

Open
mahisafa82 wants to merge 2 commits into
aiogram:dev-3.xfrom
mahisafa82:733-source-locale
Open

i18n: add source_locale parameter to I18n#1817
mahisafa82 wants to merge 2 commits into
aiogram:dev-3.xfrom
mahisafa82:733-source-locale

Conversation

mahisafa82 commented May 31, 2026
edited
Loading

Copy link
Copy Markdown

Description

Add source_locale parameter to aiogram.utils.i18n.I18n and handle it in aiogram.utils.i18n.middleware.SimpleI18nMiddleware.

When source_locale is set (defaults to default_locale), and the user's language matches it, gettext() returns the original untranslated text even if the source locale is not compiled into a .mo file.

Previously, a user with language_code matching the source language (e.g. "en") would receive the default_locale text instead of the original, because the middleware fell back to default_locale when the source locale was not found in compiled locales.

Fixes #733.

Type of change

  • Documentation (typos, code examples or any documentation update)
  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

  • tests/test_utils/test_i18n.py — added assertions for source_locale attribute, added test_init_source_locale, added test_gettext_source_locale, added test_source_locale_as_user_language
  • All existing i18n tests pass (40/40)

Test Configuration:

  • Operating System: Linux 7.0.10-2-cachyos
  • Python version: 3.13.11

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

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.
github-actions Bot added the 3.x Issue or PR for stable 3.x version label May 31, 2026

Copy link
Copy Markdown

✔️ Changelog found.

Thank you for adding a description of the changes

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Issue or PR for stable 3.x version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set source i18n language

1 participant


Back | FazBrowse Home | New Git URL