lingthio / Flask-User

Customizable User Authorization & User Management: Register, Confirm, Login, Change username/password, Forgot password and more.
http://flask-user.readthedocs.io/
MIT License
1.06k stars 294 forks source link

flask-babelex is not working when Flask-User is used #289

Open yuriymacdev opened 4 years ago

yuriymacdev commented 4 years ago

Whenever I import flask_user, flask_babelex stops working everywhere else (including the flask-user forms) in my flask app - everything defaults to English, no matter what Accept-Language is requested by the browser. I currently detoured this by using regular non-ex version of flask-babel, but flask-user forms are not internationalized, unless I localize them manually.

For flask-babel I had to use this code to make internalization work on my app (apart from flask-user forms):

@babel.localeselector
def getlocale():
    requestedLanguage = request.accept_languages.best_match(['en', 'ru', 'de'])
    print(requestedLanguage)
    if requestedLanguage:
        session['lang'] = requestedLanguage
    return session.get('lang', 'en')

Thanks

Chaostheorie commented 4 years ago

Flask User is overwriting the default domain of Flask BabelEx and due to the lack of multidomain support by Flask BabelEx it doesn't recognize your Domain (translations). I had this issue earlier and my only workaround was to overwrite the domain after the user_manager was initialized. See init.py, whcih uses a derivation of Flask Users translation_utils.py derivation