Code

Opened 5 years ago

Closed 3 years ago

Last modified 3 years ago

#11966 closed (fixed)

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

Reported by: tolano 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 claudep 3 years ago.
Fix + tests

Download all attachments as: .zip

Change History (6)

comment:1 Changed 4 years ago by ramiro

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

comment:2 Changed 4 years ago by russellm

  • Triage Stage changed from Unreviewed to Accepted

Changed 3 years ago by claudep

Fix + tests

comment:3 Changed 3 years ago by claudep

  • 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 3 years ago by jezdez

  • Resolution set to fixed
  • Status changed from new to closed

(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 3 years ago by jezdez

(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).

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.