Re: I18N prep work - convert strings to use format()

Tal Einat <[email protected]>
Newsgroups gmane.comp.python.idle
Message-ID <CALWZvp4YW2VXDRQTV4CQ8vq6gmSQ8Hk+QG9p1PBoOogNeiQBfw@mail.gmail.com>
On Wed, Jan 21, 2015 at 10:03 AM, Al Sweigart <[email protected]> wrote:
>
> I'd like to change the old-style string formatting from '%s %s' %
> (foo, bar) to the format() string method version. This is not just a
> cosmetic change, but would be part of the prep work for I18N support
> for IDLE.
>
> For some languages, the order that variables would need to be
> interpolated into strings would not be the same. For example, in
> English you could have:
>
> color = 'black'
> animal = 'cat'
> "The %s %s's toy." % (color, animal)
>
> While in Spanish, this would be:
>
> color = 'negro'
> animal = 'gato'
> "El juguete del %s %s." % (animal, color)
>
> However, this defeats translating the "The %s %s's toy." string for
> I18N. Using the format() string method fixes this: "The {color}
> {animal}'s toy." could be translated as "El juguete del {animal}
> {color}."
>
> I'd like to go through the strings in IDLE and convert them to use
> format(). This wouldn't be all of the strings: only those that are
> user-facing and have multiple %s (or other) conversion specifiers
> would need to be translated.
>
> This is a change that touches on a lot of files, so I wanted to see if
> anyone could foresee issues with this change before I start on it.
>
> -Al

Hi Al,

If i18n is your goal, are you sure that string.format() is the way to go?

string.format()'s syntax was not defined with this use-case in mind.
For example, it supports a lot of things which are not relevant for
translation, which would leave a lot of room for user errors of the
sort that use valid string.format() syntax but produce unwanted
results. A more significant drawback is that learning the syntax is
unnecessarily difficult for someone who'd just want to make a
translation.

If i18n is the goal, I strongly suggest using a tool that was made for
the purpose.

- Tal Einat
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.