Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

current_translation always default to en / english Locale #33

Open
ebursztein opened this issue Feb 19, 2023 · 0 comments
Open

current_translation always default to en / english Locale #33

ebursztein opened this issue Feb 19, 2023 · 0 comments

Comments

@ebursztein
Copy link

ebursztein commented Feb 19, 2023

Unless the use monkey patch the current_translation will always be english:
in utils.py the way the current locale is detect is this line:

locale = i18n.get_locale()

If you lookup what this does in sqlalchemy_utils/i18n.py you
find this function simply returns the babel.Locale in English

    try:
        return babel.Locale('en')

So the documentation should at least make it clear you need to monkey patch this behavior and I would also remove the dependency on this function and make it simpler how to pass your own locale detection given that there is no universal solution.

For those searching for a solution, here is how you can get it to work for Flask + Flask-Babel

def get_locale():
    if not g.get('lang', None):
        g.lang = "en"
    return g.lang

from sqlalchemy_utils import i18n
i18n.get_locale = get_locale
BABEL = Babel(app, locale_selector=get_locale)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant