[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[bug-gettext] Support the new style Python format strings

From: Rodrigo Silva
Subject: [bug-gettext] Support the new style Python format strings
Date: Mon, 09 Apr 2012 16:11:08 -0300

I've stumbled on this issue recently, and while searching if this was
already reported somewhere, I've found bug report #30854 in Savannah. Looks
like it wasn't forwarded to neither the old nor the new bug mailing list,
so I'll do it now, make his words mine, and add a few comments on my own:

Mon 23 Aug 2010 05:10:05 PM GMT, original submission by David Planella
Currently the gettext tools support only the old Python string format for
substitutions, that is, %s or %(variable)s type strings.

Python standards PEP 0292 [1] and PEP 3101 [2] recommend the use of $foo
and {foo} strings. More and more Python applications migrate to this new
syntax, and it would make sense for the gettext tools to support it.

The ones I can think, off the top of my head:

    xgettext to extract {foo} and $foo strings from Python files and mark
    them as python-format in the .pot templates
    msgmerge -c to validate those

[1] http://www.python.org/dev/peps/pep-0292/
[2] http://www.python.org/dev/peps/pep-3101/

I think he means msgfmt -c, since AFAIK there's no msgmerge -c

A few remarks on my own:

The 3 formats currently co-exist in Python 2:
  %(foo)s is used by the % operator, as in "%(foo)s" % {'foo':bar}
  {foo}   is used by the str.format() method and format() builtin,
          as in "{foo}".format(foo=bar) or format("{foo}",foo=bar)
  $foo    is used by the Template class, as in "$foo".Template(foo=bar)

The % format is deprecated in Python 3, and, while still widely used in
Python 2, its usage for new code is discouraged. format() is the new
standard. See http://docs.python.org/library/stdtypes.html#str.format

That said, I urge gettext to support at least the new format() syntax. If
it's not possible to support 3 different syntax rules simultaneously, at
least give Python users a way to choose one of the sets, using xgettext's
--flag for example

reply via email to

[Prev in Thread] Current Thread [Next in Thread]