Django

Code

Ticket #3410 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

make-messages has warnings while running xgettext on validators.py, /contrib/admin/views/doc.py, and /utils/html.py

Reported by: mirrorballu2@gmail.com Assigned to: hugo
Milestone: Component: Internationalization
Version: SVN Keywords: gettext
Cc: Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I'm getting these errors when I run

./bin/make-messages.py -l pt_BR

from the root django directory:

errors happened while running xgettext on validators.py
./core/validators.py:364: warning: '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.

Attachments

ticket-3410.diff (1.1 kB) - added by Michael Radziej <mir@noris.de> on 02/03/07 03:28:18.
changes format to dict style
ticket-3410.2.diff (1.1 kB) - added by Michael Radziej <mir@noris.de> on 02/03/07 03:30:35.
revised patch
docpatch.diff (1.5 kB) - added by mirrorballu2@gmail.com on 02/03/07 11:11:44.
A patch for doc.py

Change History

02/01/07 01:01:15 changed by Michael Radziej <mir@noris.de>

  • needs_better_patch changed.
  • stage changed from Unreviewed to Design decision needed.
  • summary changed from errors while running xgettext on validators.py to make-messages cannot deal with non-ASCII message ids.
  • needs_tests changed.
  • needs_docs changed.

Yeah, make-messages is unable to deal with message-ids that contain non-ASCII characters. It's because the way make-messages assembles the translation files doesn't allow to specify an encoding, and it's not easily fixed. I'd personally be very thankful for a patch, as I tried and was unable to fix it.

I'm dealing with this by myself with a German-German translation, i.e. in the code I use

_("Mueller")

and then I have a translation entry that translates "Mueller" to "Müller".

This is *really* nasty. I leave it to the core to decide whether this is a bug. Please take my word, this is not just a minor inconvenience.

02/02/07 21:34:01 changed by anonymous

But why are there non-ASCII characters in a core module?

02/02/07 21:36:47 changed by anonymous

The offending string appears to be "This value must be between %s and %s." and it doesn't contain any non-ASCII characters.

02/02/07 21:44:59 changed by mirrorballu2@gmail.com

Now I'm getting a different error:

./core/validators.py:364: warning: '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.

02/03/07 03:27:21 changed by Michael Radziej <mir@noris.de>

  • has_patch set to 1.
  • summary changed from make-messages cannot deal with non-ASCII message ids to make-messages has warnings while running xgettext on validators.py.

Sorry, I was reading too quickly. This really has got nothing to do with non-ASCII. It's just a (good) recommendation to use %(name)s formats instead of %s, but it's not a bug.

I've attached a patch to fix it, but I don't know if it's worth and what the general policy regarding formats in message id is, so I pass it on as "decision needed".

02/03/07 03:28:18 changed by Michael Radziej <mir@noris.de>

  • attachment ticket-3410.diff added.

changes format to dict style

02/03/07 03:30:35 changed by Michael Radziej <mir@noris.de>

  • attachment ticket-3410.2.diff added.

revised patch

02/03/07 03:31:33 changed by Michael Radziej <mir@noris.de>

Note: You'll need to run

make-messages -l de 

after applying the patch.

02/03/07 10:49:32 changed by mirrorballu2@gmail.com

  • summary changed from make-messages has warnings while running xgettext on validators.py to make-messages has warnings while running xgettext on validators.py and /contrib/admin/views/doc.py.

Thanks for the patch, it worked. But...

errors happened while running xgettext on doc.py
./contrib/admin/views/doc.py:171: warning: '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.
./contrib/admin/views/doc.py:183: warning: '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.
./contrib/admin/views/doc.py:214: warning: '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.

02/03/07 11:11:44 changed by mirrorballu2@gmail.com

  • attachment docpatch.diff added.

A patch for doc.py

02/03/07 11:14:18 changed by mirrorballu2@gmail.com

  • summary changed from make-messages has warnings while running xgettext on validators.py and /contrib/admin/views/doc.py to make-messages has warnings while running xgettext on validators.py, /contrib/admin/views/doc.py, and /utils/html.py.

Now one last error:

errors happened while running xgettext on html.py
xgettext: Non-ASCII string at ./utils/html.py:10.
          Please specify the source encoding through --from-code.

02/03/07 11:44:30 changed by ramiro <rm0 _at_ gmx.net>

@mirrorballu2,

What version of xgettext are you using?. Mine is

xgettext (GNU gettext-tools) 0.14.4
Copyright (C) 1995-1998, 2000-2005 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Ulrich Drepper.

and I don't get any warnings in Django SVN trunk as today.

Just curious about if it is an older or a newer version of xgettext the one generating these (good) warnings.

02/03/07 13:17:43 changed by mirrorballu2@gmail.com

It's a newer version.

xgettext (GNU gettext-tools) 0.15
Copyright (C) 1995-1998, 2000-2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Ulrich Drepper.

02/10/07 04:20:22 changed by mtredinnick

  • stage changed from Design decision needed to Ready for checkin.

Why is this in "design decision needed"? Looks like an oversight, because the patch looks perfect (you cannot use positional args in translated strings, so they should be fixed). I'm going to break with protocol slightly and move this ahead a couple of steps in the production line.

The problem with working with multiple versions of xgettext is a separate issue and is a source of never-ending teeth grinding for people working with the gettext tools across different versions. That should be a separate ticket if it really is a problem.

02/14/07 18:26:05 changed by mtredinnick

  • stage changed from Ready for checkin to Design decision needed.

Looking over this with my brain turned on, I now see why Michael wanted a call made on this one. It's only generating a warning, not an error. I suspect it's still the right thing to do, to make this change, but I'm going to hold off for a little while until I look at whether we are being consistent throughout Django (I suspect we are because otherwise there would be more warnings). Then I'll update i18n.txt as well.

03/12/07 03:35:15 changed by mtredinnick

  • status changed from new to closed.
  • resolution set to fixed.

(In [4704]) Fixed #3410 -- Edited a few i18n markups for completeness and to remove some warnings from recent gettext versions. Refs #3704. Thanks, Michael Radziej, mirrorballu2@gmail.com and baptiste.goupil@gmail.com.


Add/Change #3410 (make-messages has warnings while running xgettext on validators.py, /contrib/admin/views/doc.py, and /utils/html.py)




Change Properties
Action