Closed WokoLiu closed 3 years ago
I've been tracking through the code and came to the same conclusion (I doubted myself as it's seems pretty odd). It's this function:
def _get_current_context():
if has_request_context():
return request
if current_app:
return current_app
which could be optimised. Unfortunately it's a global function, i.e. not in the Babel class, so is hard to override :-(
The forked Flask-BabelEx project cites this as the reason for it to exist. Unfortunately it doesn't seem as well maintained.
Resolved in v2.0.0, pending release.
This is great in production, but is there a way to get the previous behavior in debug mode, for example?
When I use
flask_babel.gettext
function, I found that it would walk all theBABEL_TRANSLATION_DIRECTORIES
to find and load locate&translations every request.Is it necessary? Why we do this? Maybe we can load all the
.mo
file before every real request?Or do I use it wrong?
Here is my
localeselector
.Please tell me I'm wrong... Thanks