python-babel / flask-babel

i18n and l10n support for Flask based on Babel and pytz
https://python-babel.github.io/flask-babel/
Other
432 stars 159 forks source link

Add support for multiple domains #194

Closed amercader closed 1 year ago

amercader commented 2 years ago

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 python-babel/flask-babel#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:

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.

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