flask-babel

Flask + Flask-Security + Babel not working

浪子不回头ぞ 提交于 2020-01-05 05:29:47
问题 I have setup with Flask + Babel + Flask Security. Created all translation like this: root main.py translations ru LC_MESSAGES messages.mo messages.po In main.py there is part to setup language which executes: @babel.localeselector def get_locale(): user = getattr(g, 'user', None) if user is not None: print("User locale {}".format(user.locale)) return user.locale # I put here constant to test return 'ru' But http://localhost/login stayed untranslated. Can you please advice where else to dig?

Flask-Babel not working on the login page

∥☆過路亽.° 提交于 2019-12-08 11:48:05
问题 I have a Flask/Dash app that uses the Flask-Babel module. The translation works like a charm after logging in and browsing through pages. However, I cannot make it work for the login page which will always be displayed in English. The messages.po and messages.mo both contain the translation strings I prepared for the login page, so the compilation part seems to work fine. Here's a snippet from my app.py (with a hard-coded choice of Spanish): import dash from dash.dependencies import Input,

Change language Flask Babel manually

假如想象 提交于 2019-12-01 01:57:24
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 the location to english? Is there any way to change the locale manually? This is my Flask Babel function that gets the user locale and returns the language. It is on my __init__.py file. @babel.localeselector def get_locale(): print "LANGUAGE PT" #return 'de' -> manually change to the desired language request.accept_languages.best_match(LANGUAGES.keys()) I really appreciate any help! Best regards A good way to do this is

translating strings from database flask-babel

笑着哭i 提交于 2019-11-30 20:30:02
I'm using Flask-Babel for translating string. In some templates I'm reading the strings from the database(postgresql). How can I translate the strings from the database using Flask-Babel? It's not possible to use Babel in database translations, as database content is dynamic and babel translations are static (they didn't change). If you read the strings from the database you must save the translations on the database. You can create a translation table, something like (locale, source, destination), and get the translated values with a query. I would suggest having a engineering text in the

Change language Flask Babel manually

依然范特西╮ 提交于 2019-11-30 20:12:01
问题 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 the location to english? Is there any way to change the locale manually? This is my Flask Babel function that gets the user locale and returns the language. It is on my __init__.py file. @babel.localeselector def get_locale(): print "LANGUAGE PT" #return 'de' -> manually change to the desired language request.accept