Skip to content

Keep translation domains isolated when sharing Babel across apps - #249

Open
ac1982 wants to merge 1 commit into
python-babel:masterfrom
ac1982:fix/application-owned-translation-domain
Open

ac1982 wants to merge 1 commit into
python-babel:masterfrom
ac1982:fix/application-owned-translation-domain

Conversation

@ac1982

@ac1982 ac1982 commented Oct 13, 2026

Copy link
Copy Markdown

When one Babel instance initializes two Flask apps, Babel.domain_instance caches the first app’s Domain on the shared extension. Requests to the second app can therefore use the first app’s translation catalog and domain, even though the rest of its Babel configuration is application-specific. This is reproducible through ordinary Flask requests rendering Jinja gettext and calling ngettext.

Cache the default Domain on the existing application-owned BabelConfiguration and have Babel.domain_instance delegate to it. This preserves catalog reuse across requests while separating applications and resetting the cache when an app is reinitialized. No global application registry or per-request catalog reload is needed. This addresses a remaining translation-cache path in the multi-app use case from #107.

Five regression cases fail on current master and pass with this change. They use compiled catalogs and cover equal/different domains, both first-request orders, repeated requests and loader call counts, nested contexts, reinitialization, and an explicit request-local Domain override.

Validation on Python 3.8 and 3.12: 35 tests pass, with 3 pre-existing list-translations ordering failures. The unchanged base has those exact same 3 failures (30 passing); #242 separately addresses that ordering. Black 24.4.2 checks the whole repository successfully and the Sphinx documentation builds. Windows/macOS/PyPy were not run locally.

Developed and tested with OpenAI Codex assistance.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant