Open youtux opened 3 years ago
Also, even if marking the .po file manually, pybabel compile
doesn't handle the #, python-brace-format
properly:
(...)
#: somefile.py:1363
#, python-brace-format
msgid "Percentil 95% da Validação 1: {}"
msgstr "95% percentile of Validation 1: {}"
pybabel compile -d . -i translations.po -l en -f --statistics
122 of 122 messages (100%) translated in translations.po
error: translations.po:518: placeholders are incompatible
compiling catalog translations.po to .\en\LC_MESSAGES\translations.mo
1 errors encountered.
Using Anaconda3 64-bit, Python 3.8.13, babel 2.10.1, Windows 10.
While pybabel indicates the error, it also says that all messages were translated. Gotta test it properly though.
This is a problem affecting the extraction of string from python files.
While format strings like
"Hello %(name)s"
are correctly extracted and marked with the#, python-format
marker, strings like"Hello {name}"
are not marked, and translators may not realize that and change the formatting part, resulting in KeyErrors when actually evaluating the string.xgettext
will mark them correctly, with the#, python-brace-format
marker.How to reproduce
Run pybabel extraction:
The
asd.babel.po
contains these entries:The last entry is not marked as a format string.
Run the following command to check what instead
xgettext
does:The
asd.xgettext.po
contains these entries:Note that the last string is marked as
#, python-brace-format
.Use case
I have this problem when automatically translating using podebug to generate catchy unicode strings for development purposes. The tool will not see that
"hello {name}"
is a format string, and it will translate it to"ħḗŀŀǿ {ƞȧḿḗ}"
, causing a KeyError when calling_("hello {name}").format(name="Alessio")
. This can be a problem when using tools like Transifex that protect you from touching part of the string that you shouldn't. If they are not marked correctly, the tool can't do much.