Python internationalization library with an emphasis on web-based applications. Use with the [python] tag and any relevant version tags.
Questions tagged [python-babel]
158 questions
7
votes
4 answers
Change Flask-Babel locale outside of request context for scheduled tasks
I run a job every hour that can send an email to users. When the email is sent, it needs to be in the language set by the user (saved in the db).
I can't figure out a way to set a different locale outside of a request context.
Here is what I would…

mickael
- 315
- 4
- 9
7
votes
1 answer
Flask-Babel updating of existing messages.pot file
How to update an existing messages.pot file?
For example, I have translated messages.pot file:
....
#: forms.py:11
msgid "Nickname"
msgstr "Имя"
#: forms.py:18
msgid "Wrong email"
msgstr "Неправильный пароль"
....
If I'll mark new text with…

user2782936
- 133
- 1
- 5
7
votes
4 answers
Extracting Javascript gettext messages using Babel CLI extractor
It is stated here that Babel can extract gettext messages for Python and Javascript files.
Babel comes with a few builtin extractors: python (which extracts
messages from Python source files), javascript, and ignore (which
extracts…

Basel Shishani
- 7,735
- 6
- 50
- 67
6
votes
0 answers
How to localize my wtform?
I have a form that I want to localize from English to many languages. I can do it either with gettext or the datastore and I've chosen gettext for performance but I could also use the datastore to store my translations. The actual translations are…

Niklas Rosencrantz
- 25,640
- 75
- 229
- 424
6
votes
1 answer
How to register a Pylons translator object?
I've got an application that runs in several processes (one webserver and few processes that are used for heavy calculations). The goal is to make these calculation processes return localized errors. In order to do that, I've made a dictionary that…

Ivan Gromov
- 4,195
- 9
- 41
- 57
6
votes
2 answers
Switch language in jinja template
I'm migrating a multi lingual Django application from Django's template engine to Jinja2. In the templates I currently switch the active language on a per object basis using Django's language template tag i.e.:
{% load i18n %}
{% trans 'Page…

jaap3
- 2,696
- 19
- 34
6
votes
2 answers
Flask-Babel localized strings within js
I'm pretty new to both Python and Flask (with Jinja2 as template engine) and I am not sure I am doing it the right way. I am using Flask-Babel extension to add i18n support to my web application. I want to get localized strings from my js code, for…

jarandaf
- 4,297
- 6
- 38
- 67
6
votes
1 answer
Translate default errors in Flask-WTF
I am trying to translate the default messages from WTForms using the Flask-WTF plugin.
According to this(https://github.com/ajford/flask-wtf/pull/65) it should be working. You can also see that wtforms use gettext for their default error…

kechap
- 2,077
- 6
- 28
- 50
6
votes
4 answers
Babel doesn't recognize jinja2 extraction method for language support
I'm adding language translation support to my project. The code is on Python and has jinja2 in the html files, and Javascript.
I'm trying to use Babel to do the translation, but it doesn't recognize the extraction method of jinja2. Maybe I'm using…

user1612990
- 61
- 1
- 4
5
votes
2 answers
Get translatable text from an external source into catalog
Possibly i am overlooking an obvious solution or thinking the wrong way...
I have a limited amount of text, words in a database, that I want to display translated to users in a flask/jinja/babel webapp. eg. "running" is a possible value of an…

Florian
- 2,562
- 5
- 25
- 35
5
votes
1 answer
How to set blank default locale for a flask app?
I am working on a flask project (Python3). I have internationalization working fine in my project. This is the configuration method launched in the create_app factory:
def configure_languages(app):
# flask-babel
babel = Babel(app)
…

Nurjan
- 5,889
- 5
- 34
- 54
5
votes
1 answer
Unit testing Flask Babel translations
I'd like to do some unit tests to check my flask app translations. I have tried this piece of code:
def test_pt_br(self):
with app.test_request_context():
app.config['BABEL_DEFAULT_LOCALE'] = 'pt_BR'
rv =…

andref
- 750
- 5
- 20
5
votes
3 answers
Flask Babel Translations path
I have a webapp that uses Flask Babel to translate the templates.
This webapp can use multiple databases by adding the database name to its url, like:
myapp.com/
The problem is that translations path is hardcoded in babel:
def…

xyro
- 465
- 1
- 6
- 25
5
votes
4 answers
How to use Pyramid i18n outside of views and templates?
Pyramid documentation shows us how to use i18n inside views (and templates as well). But how to does one use it outside of views and templates where we have no access to current request (for example, in forms and models)?
@Michael said to pass…

Vitalii Ponomar
- 10,686
- 20
- 60
- 88
4
votes
2 answers
AttributeError: module 'jinja2.ext' has no attribute 'autoescape' while trying to use Flask-Babel
I am new to Flask and Babel and I have just started a project which will contain several languages. After I have generated the babel.cfg file, when I attempt to extract it with the command pybabel extract -F babel.cfg -o messages.pot ., I get the…

mbaki
- 57
- 1
- 5