Add support for multiple domains#194
Merged
TkTech merged 2 commits intoJan 8, 2023
Merged
Conversation
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`.
6 tasks
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
This was referenced Mar 9, 2023
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
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:
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:
flask-babel/flask_babel/__init__.py
Line 564 in ec7ae9e
This change adds support for a semi-colon separated list of domains in
BABEL_DOMAIN, that must match a list passed toBABEL_TRANSLATION_DIRECTORIES.I'm not sure if there is a more elegant way to achieve the same result but happy to change the approach.