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
2
votes
3 answers
Internationalization with python gae, babel and i18n. Can't output the correct string
jinja_env = jinja2.Environment(loader = jinja2.FileSystemLoader(template_dir),extensions=['jinja2.ext.i18n'], autoescape = True)
jinja_env.install_gettext_translations(i18n)
config['webapp2_extras.i18n'] = {
'translations_path': 'locale',
…

tipsywacky
- 3,374
- 5
- 43
- 75
1
vote
2 answers
using unix timestamp generate timedelta for babel's format_timedelta
I am not sure I worded that correctly but python and time always confuses me.
This is what I am trying.
Given a unix timestamp (INT) which is definitely in the past (can be seconds ago or years ago) I want to generate a babel format_timedelta
My…

Abhishek Dujari
- 2,343
- 33
- 43
1
vote
1 answer
How to enable timezones with babel in my jinja filter?
I want to use timezones according to the babel locale. How can I achieve this? The specific situation I have is the goal of displaying the date and time of an article and a humanized and localized way eg:
Yesterday
13:21
or if the Swedish language…

Niklas Rosencrantz
- 25,640
- 75
- 229
- 424
1
vote
1 answer
Babel - Using both `msgstr` and `msgid` without duplicate static strings
Take this as an example while I tried to minimize code duplication.
msg = 'User request is completed'
logging.info(msg)
reply(_(msg)) # Babel would failed to extract the variable `msg`.
I know babel cannot extract variables but I'd like to…

Louis Go
- 2,213
- 2
- 16
- 29
1
vote
1 answer
Stringformat a MultiIndex DatetimeIndex using Babel's format_datetime() for Localization
Python 3.7.0
pandas 1.1.5
numpy 1.21.4
Babel 2.9.1
Problem
I have a dataset that is first evaluated, then completed with calculations and then converted into a pd.MultiIndex by grouping it with the pd.Grouper. The result looks something like…

bhthllj
- 21
- 6
1
vote
0 answers
Why is the dictionary not translated with Flask-Babel
I am writing a website in Flask. I use Flask-Babel for translation into different languages. I use lazy_gettext to translate dictionary values. When changing the language on the site, all phrases and sentences that I wrapped should be translated.…

Яша Проценко
- 45
- 1
- 4
1
vote
3 answers
"module 'babel' has no attribute 'dates'" when trying to format time and date
I have written this function to format time and date in my Flask app with Babel:
import babel
from flask import Flask
app = Flask(__name__)
def format_datetime(value, format='medium'):
if format == 'full':
format = "EEEE MMMM, d, y…

TheTruth
- 37
- 7
1
vote
3 answers
How to get specific string translation which is not currently the locale?
Let's say I have a string in English, locale="en", e.g. "computer" and its Spanish translation, locale="es" translation, would be "computadora".
If the website is currently set to English, how could still access that specific string but translated…

Al Nikolaj
- 305
- 4
- 13
1
vote
1 answer
Flask-Babel localeselector is not being called
Flask-babel doesn't call its localeselector even once. I'm using app factory to init my app. The translations folder is within my app, It was created by babel, according to the docs. I've also tried moving the translations dir to the folder…

nieomylnieja
- 39
- 1
- 6
1
vote
2 answers
Translate string with python babel doesn't work
I have this python line
raise ValueError(_(u'Your password must be {} of characters or longer.'.format(MIN_PASSWORD_LENGTH)))
I added it to the PO file:
msgid "Your password must be {} of characters or longer."
msgstr "Votre mot de passe doit être…

Felix
- 25
- 8
1
vote
1 answer
Set html tag lang attribute accordingly using flask babel
Looking at the docs I find no mention to this pretty basic and common need:
I want to set the html tag lang attribute according to selected locale -- without passing it explicitly every time to render_template, e.g.
Only…

neurino
- 11,500
- 2
- 40
- 63
1
vote
1 answer
Babel not returning languages?
I'm trying to use Babel 2.6.0 to get the "official" language(s) by territory but it returns nothing.
As seen here, it should take a two letter territory code.

Travis
- 358
- 3
- 13
1
vote
0 answers
Scientific number format with Python Babel
I'm trying to print a number in a scientific number format (with exponent) using the package babel and a German locale:
>>> from babel.numbers import format_scientific
>>> x = 123456.789
>>> format_scientific(x, format="0.000E0",…

Jan
- 892
- 6
- 7
1
vote
1 answer
How to use Flask-Babel gettext in Flask-WTForms render_kw?
I'm starting using Babel with WTForms and Flask. Below I try to gettext the placeholder keywords for my Username and Password fields :
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask_babel import gettext
from flask_wtf import…

Benjamin
- 65
- 1
- 8
1
vote
1 answer
Flask-Babel fail to extract UTF-8 content
I have a translatable string in one of my Jinja2 templates:
Project can’t end sooner than it starts
(Note the UTF-8 apostrophe in “can’t”.)
When I extract messages and update my translation files, both the template (.pot) and translation (.po)…

GergelyPolonkai
- 6,230
- 6
- 35
- 69