… also known as Python Tip of the Day:

What’s wrong (translation-wise) on this snippet of python code?

random = _("Lorem ipsum dolor sit amet, " +
           "consectetur adipisicing elit")

You are not going to see any warning on your code, if you don’t have this message translated you will never notice…

But unfortunately, as soon as you have this message translated you will notice that only half of the string is translated, which for Arabic or other RTL1 languages can be quite funny…

So, you already noticed right?

Turns out that gettext gets confused by the plus sign! As you already may remember by now, Python can join multiple strings just by putting them together, no need for a plus sign. Try it yourself on your python console:

>>> print ("Lorem " " ipsum" " dolor"
... " amet")
Lorem  ipsum dolor amet

So dear Python developers out there, pretty please double check your strings marked for translation, if not a translator will find out, hopefully before a release, and report it back :)

Planet GNOME

Seems that I pestered enough our (that sound good!) planet editor2 that he finally added me in. Hi GNOMEr’s around the globe!!

I’m Gil Forcada, Coordinator of the Catalan Translator Team, member of the Localization Coordination Team, nowadays also Damned-Lies maintainer and usually you see me on GUADEC’s behind the info desk :D

I’m all digital ears to digitally hear anything related to l10n/i18n and how to move GTP3 forward!

Edit: fixed the \ on the second code snippet (no need for that) and the LTR to RTL! Oh my!

  1. Right to Left []
  2. Wo was so nice to also create my planet hackergotchi! []
  3. GNOME Translation Project []

6 pensaments quant a “PTotD”

  1. Python tip of the day:

    When in open parenthesis, bracket or brace, don’t use \ for line continuation. It’s superfluous and ugly :)

  2. Heya Gil :)

    I’ll +1 on what Patryk has said. FWIW, the style you are using is usually referred to as the C-style string continuation, and xgettext, being originally designed for C, supports it very well.


  3. P.S. Maybe it’s because I’m a gettext newbie, but the article wasn’t very clear. For a moment I thought that the code is broken and I was wondering how can the gettext.gettext function (aliased as _) be affected by how its parameter is constructed. I had to do a little experiment to figure out that you were actually talking about the generation of the message catalog. Perhaps you should have been more explicit about what’s going on.

Deixa un comentari

L'adreça electrònica no es publicarà. Els camps necessaris estan marcats amb *