[sugar] internationalization problem

Erik Blankinship erikb at mediamods.com
Fri Jan 4 19:14:31 EST 2008


Sometimes translators have to include variables in their translations.

Most po files have their source strings set up using just %s as the variable
name.

>>> test = "hi there %s"
>>> test % 'erik'
'hi there erik'


However, the order of those variables might be different in different
languages.  That is why we set up our strings like this:

>>> test2 = "hi there %(1)s and %(2)s"
>>> test2 % {"1":"erik", "2":"michael"}
'hi there erik and michael'

The translators successfully copied these variable place holders into their
strings.  That was not a problem for the translators.

The problem is that the variable names in their .po files don't come through
the process of making a .xo package.  %(1)s becomes %(1).  This causes
gettext to break.

We just tested using %s for all of our strings, and that works.  We can
quickly revert to that (hoping the phrases we asked to be translated didn't
require resequencing of variables).

It seems that there might be a bug in the process that is generating the
locale information from the po files.


On 1/4/08, Walter Bender <walter at laptop.org> wrote:
>
> the problem is that your asking the translator to not just translate
> strings, but also your python code. that won't work.
>
> -walter
>
> On Jan 4, 2008 4:45 PM, Erik Blankinship <erikb at mediamods.com> wrote:
> > Trying to run Record in Spanish is causing a problem.  I will outline
> the
> > steps which create this problem.  Hopefully someone can clarify where
> the
> > bug is.
> >
> > In Constants.py, we define the following string:
> >
> >  #TRANS: photo by photographer, e.g., "Photo by Mary"
> > istrBy = _("%(1)s by %(2)s")
> >
> > Which was picked up when we ran python genpot to create Record.pot.
> >
> > A translator kindly translated Record.pot into Spanish to create es.po:
> >
> > #. TRANS: photo by photographer, e.g., "Photo by Mary"
> > #: constants.py:99
> > #, python-format
> > msgid "%(1)s by %(2)s"
> > msgstr "%(1)s por %(2)s"
> >
> > Then, we created Record-49.xo by running python setup.py dev and python
> > setup.py dist in the sugar shell.  This creates and populates the locale
> > directory with lots of files.
> >
> > Then we install the program on an xo and run it.
> >
> > Then we take a picture, and that process tries to assign metadata to a
> > datastory entry, but crashes with this stack trace:
> >
> > --> 371         recd.title = Constants.istrBy % {"1":stringType,
> > "2":str(recd.recorderName)}
> >         recd.title = None
> >         global Constants.istrBy = '%(1) por %(2)'
> >          stringType = 'Foto'
> >         global str = undefined
> >          recd.recorderName = u'dude face'
> > ...
> >  <type 'exceptions.ValueError'>: unsupported format character 'p' (0x70)
> at
> > index 5
> >
> > What is strange is the line Constants.istrBy = '%(1) por %(2)'
> >
> > This string appears to have lost its "s" at the end of the (1) and the
> (2)
> > (which we can see were included in the es.po file above).  I am not sure
> how
> > this would have happened, but it does seem to make some sense of the
> error
> > (the p character being the first thing interpreted after where an s was
> > expected.
> >
> > Any ideas on where we're doing something wrong?  Thanks.
> >
> > Erik
> > _______________________________________________
> > Sugar mailing list
> > Sugar at lists.laptop.org
> > http://lists.laptop.org/listinfo/sugar
> >
> >
>
>
>
> --
> Walter Bender
> One Laptop per Child
> http://laptop.org
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.laptop.org/pipermail/sugar/attachments/20080104/6c90187a/attachment-0001.htm 


More information about the Sugar mailing list