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

Another difference between Flask-BabelEx - jinja initialization #178

Closed jwag956 closed 1 year ago

jwag956 commented 3 years ago

Specifics: As part of init_app(): Flask-BabelEx:

app.jinja_env.install_gettext_callables(
                lambda x: get_domain().get_translations().ugettext(x),
                lambda s, p, n: get_domain().get_translations().ungettext(s, p, n),
                newstyle=True
            )

And Flask-Babel:

app.jinja_env.install_gettext_callables(
                lambda x: get_translations().ugettext(x),
                lambda s, p, n: get_translations().ungettext(s, p, n),
                newstyle=True
            )

So Flask-Babel doesn't take into account the 'default domain' as specified in the init function.

Dialogue: This was never clear to me and and seems like a missing link with Flask* an Babel - how applications could have translations and messages and domains but still utilize 3rd party library translations and messages - seems like Domains wasn't really thought through (or I don't understand it!).

For Flask-Security - I have already introduced a library specific jinja function (_fsdomain) that me tag my templates to be translated not with the default domain but with a specific domain.

Anyway - this change will break many things - so at a minimum I would suggest a release note/documentation...

TkTech commented 1 year ago

Our (flask-babel) call to get_translations() is just a shortcut for get_domain().get_translations(), see https://github.com/python-babel/flask-babel/blob/2a994898d989207043f06a859aec43bf510470ee/flask_babel/__init__.py#L207-L207. Unless I'm missing something here, this seems to be a non-issue as they are functionally identical