Change language Flask Babel manually

后端 未结 1 1730
轮回少年
轮回少年 2021-01-07 06:03

I\'m using Flask Babel to translate my Flask Python app. At moment I only have the translation mechanism by locale but what if the user besides his location wants to change

相关标签:
1条回答
  • A good way to do this is shown in the docs of Flask-Admin

    @babel.localeselector
    def get_locale():
        if request.args.get('lang'):
            session['lang'] = request.args.get('lang')
        return session.get('lang', 'en')
    

    Now, you could try a French version of the application at: http://localhost:5000/admin/?lang=fr.

    You can still specify the default language via BABEL_DEFAULT_LOCALE.

    0 讨论(0)
提交回复
热议问题