flask-humanize
flask-humanize copied to clipboard
Flask-humanize does not set default_locale
It seems in app_has_babel() a app.extensions.get("babel").default_locale is more appropriate than app.config['BABEL_DEFAULT_LOCALE']?
Underscore format it_IT instead of bare "it" currently returned by Babel seems to need a design shift.
I'm using this in main.py application factory but it still not works:
@humanize.localeselector
def get_locale():
locale = current_app.extensions.get("babel").default_locale
return f"{locale.lower()}_{locale.upper()}"
This also do not sound:
@property
def default_locale(self):
"""Returns the default locale for current application."""
return current_app.config['HUMANIZE_DEFAULT_LOCALE']
app.extensions.get("humanize").default_locale
Traceback (most recent call last):
File "<string>", line 1, in <module>
File ".venv/lib/python3.11/site-packages/flask_humanize/__init__.py", line 105, in default_locale
return current_app.config['HUMANIZE_DEFAULT_LOCALE']
^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/werkzeug/local.py", line 318, in __get__
obj = instance._get_current_object()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File ".venv/lib/python3.11/site-packages/werkzeug/local.py", line 519, in _get_current_object
raise RuntimeError(unbound_message) from None
RuntimeError: Working outside of application context.
This typically means that you attempted to use functionality that needed
the current application. To solve this, set up an application context
with app.app_context(). See the documentation for more information.