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

Use w/o initialization #175

Closed jwag956 closed 1 year ago

jwag956 commented 3 years ago

First and foremost - thank you thank you thank you for getting the Domain/BabelEx features backported into a supported package...

In PR #163 it was stated:

'we did not keep support flask-babelex had for using the flask extension without having initialized it. to me that looks very much like supporting something that's not expected to work anyway..'

Here is a use case for that - I am moving Flask-Security-Too to use Flask-Babel from Flask-BabelEx. Flask-Security has translations for all its messages, and requires Flask-Babel as a dependency.

However - not all application that USE Flask-Security care about i18n and therefore have no reason to initialize Babel. In the past - it just worked - Flask-Security initialized its Domain and since no locale changes were actually configured - it was fine.

But now of course it breaks if the application doesn't init Flask-Babel. This puts a burden on the application. If Flask-Security looks at whether Flask-Babel is registered as an extension - it then requires that different extensions have an implied order of initialization (and there isn't a way to tell the application writer that translations were ignored since we didn't find a Flask-Babel extension).

jwag956 commented 3 years ago

So - I have added code to Flask-Security that works with Flask-BabelEx, Flask-Babel, and neither - along with a runtime check for whether Flask-Babel has been initialized. So that covers it for me - not optimal but.... feel free to close this if you disagree with the premise...

TkTech commented 1 year ago

I don't think we're ever going to support this. We are a flask extension and we depend on having an application context. If someone has a clean way of doing this with minimal changes, we'll accept it.0