Skip to content

Add support for multiple domains#194

Merged
TkTech merged 2 commits into
python-babel:v2.1.0from
amercader:support-for-multiple-domains
Jan 8, 2023
Merged

Add support for multiple domains#194
TkTech merged 2 commits into
python-babel:v2.1.0from
amercader:support-for-multiple-domains

Conversation

@amercader

Copy link
Copy Markdown
Contributor

Adds support for loading translations from different domains in the same Flask-Babel instance.

To be clear, our application (CKAN) supports the following setup for translations:


/path/to/core/translations/ckan.pot

/path/to/ckanext-ext1/translations/ckanext-ext1.pot

/path/to/ckanext-ext2/translations/ckanext-ext2.pot

After the refactor in #163 there is no longer support for defining different translation domains for different translation directories. @ThiefMaster mentioned in #163 that it superseded the now closed #148, but I haven't been able to figure out how multiple domains could be supported in the new version. AFAICT, when loading the translations, a single domain is always used, thus preventing loading translations from directories that use a different domain:

This change adds support for a semi-colon separated list of domains in BABEL_DOMAIN, that must match a list passed to
BABEL_TRANSLATION_DIRECTORIES.

I'm not sure if there is a more elegant way to achieve the same result but happy to change the approach.

Adds support for loading translations from different domains in the
same Flask-Babel instance.

After the refactor in python-babel#163 there was no longer
support for defining multiple translation domains for different
translation directories. When loading the translations, a single domain
was always used:

https://github.com/python-babel/flask-babel/blob/ec7ae9ed2e22c7aebd4e732c1c3dc6d45fe8db76/flask_babel/__init__.py#L564

This change adds support for a semi-colon separated list of domains in
`BABEL_DOMAIN`, that must match a list passed to
`BABEL_TRANSLATION_DIRECTORIES`.
@TkTech TkTech merged commit 38145ee into python-babel:v2.1.0 Jan 8, 2023
amercader added a commit to amercader/flask-babel that referenced this pull request Mar 9, 2023
There is no `BABEL_DOMAINS`, is just `BABEL_DOMAIN`. I introduced this back in  python-babel#194
amercader added a commit to ckan/ckan that referenced this pull request Mar 9, 2023
After updating to the latest Flask Babel version that includes
python-babel/flask-babel#194, we don't need to monkey patch the Flask
Babel middleware anymore and can pass the multiple translation domains
from extension via the `BABEL_DOMAIN` config option
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.

2 participants