Opened 7 years ago

Closed 6 years ago

Last modified 6 years ago

#11966 closed (fixed)

Error: errors happened while running xgettext over template file with a literal that contains '%'

Reported by: Adrian Ribao Owned by: nobody
Component: Internationalization Version: master
Severity: Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

I find an error when running

manage.py makemessages -a

The problem comes when it reads a .html file with this content:

{% blocktrans %}This is some text ... 75% ... more text ... 75% of ...{% endblocktrans %}

The error is:

Error: errors happened while running xgettext on info-tripartita.html
./templates/myfile.html.py:98: atención: 'msgid' format string with unnamed arguments cannot be properly localized:
                                                                 The translator cannot reorder the arguments.
                                                                 Please consider using a format string with named arguments,
                                                                 and a mapping instead of a tuple for the arguments.

It's ok if there is only one % symbol in the string and even if the string has no characters after the second %:

{% blocktrans %}This is some text ... 75% ... more text ... 75%{% endblocktrans %}

I can't find a way to solve this problem.

Attachments (1)

11966.patch (2.3 KB) - added by Claude Paroz 6 years ago.
Fix + tests

Download all attachments as: .zip

Change History (6)

comment:1 Changed 7 years ago by Ramiro Morales

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Summary: Error: errors happened while running xgettextError: errors happened while running xgettext over template file with a literal that contains '%'

comment:2 Changed 7 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

Changed 6 years ago by Claude Paroz

Attachment: 11966.patch added

Fix + tests

comment:3 Changed 6 years ago by Claude Paroz

Has patch: set

Attached patch (download it if Trac doesn't show it) tries a simple fix in doubling all '%' signs found inside a translatable strings. I'm not completely convinces it's safe to do so, but I think we miss some extensive tests regarding templatize results. A more clever solution would test if there is another "%(var)s" in the string, and if not, simply output a # no-python-format comment so as xgettext uses it.

comment:4 Changed 6 years ago by Jannis Leidel

Resolution: fixed
Status: newclosed

(In [14459]) Fixed #11966 -- Made it possible to use a percent sign in a translation message id. Thanks for the patch, Claude Paroz.

comment:5 Changed 6 years ago by Jannis Leidel

(In [14460]) [1.2.X] Fixed #11966 -- Made it possible to use a percent sign in a translation message id. Thanks for the patch, Claude Paroz.

Backport from trunk (r14459).

Note: See TracTickets for help on using tickets.
Back to Top