160 questions
1
vote
1
answer
97
views
Using pybabel to translate tooltip text inside a HTML tag
I've basically finished translating my flask frontend into a lot of different languages but there are a couple of tooltips that I just can't seem to figure out. Technically, these need to be strings ...
2
votes
1
answer
66
views
FastAPI template Arabic translation render from right to left
I am trying to translate Arabic for FastAPI and I created template as shown here:
<!DOCTYPE html>
<html>
<head>
<title>{{ _("Welcome") }}</title>
</head&...
1
vote
0
answers
78
views
flask babel not able to load the translated files
I am trying to translate my current flask project and I follow the step mentioned in flask-babel.
First I tried with new flask-restx app. It works fine. When I compile the messages, it get those ...
-1
votes
1
answer
176
views
Error in building project - babel module not found
I have been attempting to build and upload my project to PyPI with GitHub workflows, when an error occurs in this build section:
Here is the error itself:
File "/home/runner/work/...
0
votes
2
answers
477
views
Format currency with babel without Unicode?
Using Babel I get this:
>>> babel.numbers.format_currency(1099.98, 'CHF', locale='fr_CH')
'1\u202f099,98\xa0CHF'
I would like this format:
"CHF 1'099.98"
Is it possible to specify ...
-1
votes
1
answer
308
views
Getting an error while running an odoo-bin in odoo 15
Getting an error as ModuleNotFoundError: No module named 'babel.dates'; 'babel' is not a package while running an odoo-bin
I have clone odoo 15.0 repostiorary
i have tried to run requirement file and ...
0
votes
1
answer
196
views
Combining Eel, Jinja2, Babel - how to?
On a project where I use Eel Python and you can tell Eel to use Jinja2.
Works fine (congrats to the creators). I installed Babel, created a /lang/ folder where I store .pot and .po and .mo files after ...
0
votes
1
answer
453
views
AttributeError: module 'babel' has no attribute 'numbers'
Goal: Pass a locale code and retrieve a currency symbol.
My approach is to use babel library. However, I encounter an AttributeError in version 2.12.1.
Documentation | PDF page number: 82
Code:
import ...
2
votes
1
answer
136
views
How do I make Babel use minus signs?
Why is it that Babel does not use the minus sign used by my locale, in functions like format_decimal()? It seems to me like this would be the very job of a library like Babel.
Is there a way I can ...
3
votes
1
answer
165
views
Babel formatting error for negative values in currency
I try to format floats into currency-strings with babel. The following code:
from babel.numbers import format_currency
print(format_currency(value, 'CHF', locale='de_CH'))
print(format_currency(value,...
0
votes
1
answer
454
views
Is there a way to replace jinja2.ext.autoescape and jinja2.ext.with_ in Flask Babel?
I'm using Flask Babel for web translation:
When I write my config file like the following, it doesn't find any translations and the error is that jinja2.ext.autoescape and jinja2.ext.with_ are ...
0
votes
0
answers
943
views
failed to excute due to unhandled exception no module named babel.numbers
i built a python app with tkinter and i want to make it into an exe so i can use it as a normal app. the problem is pyinstaller is always throwing weird errors (i don't know if this has to do with ...
1
vote
1
answer
431
views
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 ...
14
votes
2
answers
8k
views
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 ...
1
vote
1
answer
146
views
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 ...
0
votes
2
answers
3k
views
jinja2.exceptions.UndefinedError: '_' is undefined
I am using flask_babel for localization of a python project.
When extracting translatable strings from templates, which is put in {{ _('') }} , i am getting the following error. If anyone of you ...
1
vote
1
answer
1k
views
Let Flask-Babel use default locale's msgstr if the msgstr in the requested locale is empty
We would like to use Flask-Babel for the internationalizing of our Flask application.
Our goal is to use a unique ID string like "example_demo_text" for msgid and translate this msgid in ...
1
vote
1
answer
68
views
xgettext fails to extract tag attributes
I'm stuck with xgettext missing tag attributes in HTML templates, e.g.:
xgettext --keyword=_ --language=Python -o - - <<EOF
<!DOCTYPE html>
<html>
<head>
% msg = _('A ...
0
votes
2
answers
2k
views
Flask Babel RuntimeError: Working outside of request context
I tried to set up multiple Dash Apps inside a Flask App and use Flask Babel.
from flask import Flask, request
from flask_babel import Babel, gettext
from werkzeug.middleware.dispatcher import ...
0
votes
2
answers
1k
views
How to translate .po file
I have a flask app and i wanted to add multiple languages to it. So i have using this demo on Flask_babel to do this.
Flask Label Demo
config.py
DEBUG = True
LANGUAGES = ['en', 'de', 'fr']
This is ...
0
votes
1
answer
154
views
How do get python to output _("95% confidence interval") correctly?
I have a very frustrating issue. I need the string "95% confidence interval" to appear on in a web view. And I need to have it translatable (using babel) so I'm using it like this:
_("...
0
votes
2
answers
3k
views
Format float to currency using PySpark and Babel
I'd like to convert a float to a currency using Babel and PySpark
sample data:
amount currency
2129.9 RON
1700 EUR
1268 GBP
741.2 USD
142.08091153 EUR
4.7E7 ...
1
vote
0
answers
146
views
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 ...
1
vote
3
answers
2k
views
"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 ...
0
votes
1
answer
966
views
How to set use_locale on Flaks wtform DecimalField?
I've been trying to set 'use_locale' parameter for wtform DecimalField, but nothing seems to work and there's barely any examples on how to set 'use_locale'. I've been through the documentation from ...
0
votes
1
answer
2k
views
How to dynamically switch jinja filter
I am currently making a web app that displays a list of transactions of the user. I want to make a setting to change the currency from USD to EUR. I am using custom filter in jinja:
My custom filter ...
1
vote
2
answers
383
views
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 ...
2
votes
1
answer
2k
views
Flask-Babel language selector
Hello it is a pleasure to greet you, today I come to ask you for help with an error that Babel de Flask is presenting to me, I am new to the subject, but in advance I thank you for your collaboration.
...
3
votes
1
answer
3k
views
How to use React and material-ui with flask backend?
I am a beginner with react. I was just trying to make a web app with flask backend and react frontend with material-ui but I was facing problems with setting it up.
What I did
I downloaded the React ...
3
votes
0
answers
95
views
Possible to create custom locale, such as fr_EN?
I am looking for a possibility to create a custom locale for my website. The website is available in several languages, including French. The French version of the website has particular content which ...
0
votes
1
answer
1k
views
How to use translation in Flask?
I have an application in which I have managed to use translations for romanian and english. I want to press the button "english" and get the website translated in english and when pressing &...
4
votes
1
answer
3k
views
How to change language of flask babel on a button click?
I have the function in Flask, which returns the website in english. Moreover, i want to be able to use german in the website at a button push from html. How can I change the language at a button push ...
2
votes
0
answers
1k
views
Get a list of translated nationality names with python and babel (or maybe something else?)
I need to write a multilingual program where users can set their home country and nationality on their profile pages. I can get a list of country names with python and babel easily.
For example, to ...
1
vote
1
answer
2k
views
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 ...
0
votes
1
answer
487
views
Flask Babel convert to original language when insert to database
I have a set of SelectField with Flask-WTF and I convert the default language with Flask-Babel.
Here is the snippet of my code:
from flask_babel import _, lazy_gettext as _l
class PaymentStatus(...
0
votes
1
answer
434
views
How to fix "ValueError: Unknown extraction method 'jinja2'" error in Python ?( Jinja2 Internationalization ?)
I need to extract messages from jinja2 files from my pyramid web app, Babel has a three default extraction method (javascript, python, ignore). How can i add Jinja2 extraction method ?
All my ...
0
votes
0
answers
478
views
How can I format a date within a longer string in a Jinja template with flask_babel?
Within a jinja template, I have the following string
# English
<p>by John Smith on <time pubdate="pubdate" datetime="2019-01-30T20:54:55">January 30, 2019</time></p>
# German
...
0
votes
1
answer
1k
views
Translation between languages with different numbers of plurals
I am trying to create a translation file in simplified Chinese from an English source. This is all happening in a Flask project and I've been using Flask-Babel (so far successfully) to translate to ...
1
vote
2
answers
560
views
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 ...
0
votes
1
answer
2k
views
Flask App not calling Babel localeselector
I am adding localisation to my Flask app with Flask-Babel, and I cannot seem to change the language. I followed all the Babel instructions for creating the po/mo files - I don't believe my issue is ...
0
votes
0
answers
53
views
Google App Engine - Python - Babel - write_mo()
I'm working on Google App Engine Python3.7
I wrote this working code based on what I learned here:
http://babel.pocoo.org/en/latest/api/messages/mofile.html
https://docs.python.org/3/library/gettext....
3
votes
2
answers
766
views
Flask, Jinja2, Babel error on "$" character
I'm migrated my code from webapp2 to Flask. (I deploy my code in Google App Engine)
However, I can no longer use this string: "Error: Max %1$d characters"
Initialization
flask_app = Flask(__name__)
...
1
vote
1
answer
511
views
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 ...
2
votes
2
answers
3k
views
How to get a specific language translation using pybabel
Most of the time, using Babel's gettext() or _() is with a current locale set within the current context, so that the target language is implicit, it is not passed as an argument to gettext().
...
1
vote
1
answer
322
views
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.
2
votes
2
answers
2k
views
How do I add a link to change and keep a new language using babel and flask?
I have setup Babel correctly and the translation work as intended. What I am stuck with is to be able to switch languages using a link and than keep that setting active even if the user click on any ...
16
votes
1
answer
9k
views
How to use python csv.DictReader with a binary file? (For a babel custom extraction method)
I'm trying to write a custom extraction method for babel, to extract strings from a specific column in a csv file. I followed the documentation here.
Here is my extraction method code:
def ...
4
votes
2
answers
1k
views
How to escape '%' character in jinja 2.10 {% trans %} using pybabel?
I am using jinja 2.10 and pybabel. When my template contains following code (with '%' char inside trans block) pybabel-compile does not translate the string. The extracted string (in .po) is OK but on ...
2
votes
2
answers
2k
views
KeyError: 'babel' - related to __init__.py - Not using Babel explicitly
I've been getting the same error for hours, no matter what code changes I make, and it's referencing Babel, a dependency I am not specifically calling or using, although I assume it's being called for ...
1
vote
0
answers
300
views
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 = ...