Sometimes translators have to include variables in their translations.<br><br>Most po files have their source strings set up using just %s as the variable name.<br><br>
<div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">>>> test = "hi there %s"</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">>>> test % 'erik'</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">'hi there erik'</span></div><br><br>However, the order of those variables might be different in different languages. That is why we set up our strings like this:
<br><span style="font-family: courier new,monospace;"></span><br style="font-family: courier new,monospace;">
<div style="margin-left: 40px;"><span style="font-family: courier new,monospace;">>>> test2 = "hi there %(1)s and %(2)s"</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">
>>> test2 % {"1":"erik", "2":"michael"}</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">'hi there erik and michael'
</span><br></div>
<br>The translators successfully copied these variable place holders into their strings. That was not a problem for the translators.<br><br>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.
<br><br>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). <br><br>It seems that there might be a bug in the process that is generating the locale information from the po files.
<br><br><br><div><span class="gmail_quote">On 1/4/08, <b class="gmail_sendername">Walter Bender</b> <<a href="mailto:walter@laptop.org">walter@laptop.org</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
the problem is that your asking the translator to not just translate<br>strings, but also your python code. that won't work.<br><br>-walter<br><br>On Jan 4, 2008 4:45 PM, Erik Blankinship <<a href="mailto:erikb@mediamods.com">
erikb@mediamods.com</a>> wrote:<br>> Trying to run Record in Spanish is causing a problem. I will outline the<br>> steps which create this problem. Hopefully someone can clarify where the<br>> bug is.<br>>
<br>> In Constants.py, we define the following string:<br>><br>> #TRANS: photo by photographer, e.g., "Photo by Mary"<br>> istrBy = _("%(1)s by %(2)s")<br>><br>> Which was picked up when we ran python genpot to create
Record.pot.<br>><br>> A translator kindly translated Record.pot into Spanish to create es.po:<br>><br>> #. TRANS: photo by photographer, e.g., "Photo by Mary"<br>> #: constants.py:99<br>> #, python-format
<br>> msgid "%(1)s by %(2)s"<br>> msgstr "%(1)s por %(2)s"<br>><br>> Then, we created Record-49.xo by running python setup.py dev and python<br>> setup.py dist in the sugar shell. This creates and populates the locale
<br>> directory with lots of files.<br>><br>> Then we install the program on an xo and run it.<br>><br>> Then we take a picture, and that process tries to assign metadata to a<br>> datastory entry, but crashes with this stack trace:
<br>><br>> --> 371 recd.title = Constants.istrBy % {"1":stringType,<br>> "2":str(recd.recorderName)}<br>> recd.title = None<br>> global Constants.istrBy = '%(1) por %(2)'
<br>> stringType = 'Foto'<br>> global str = undefined<br>> recd.recorderName = u'dude face'<br>> ...<br>> <type 'exceptions.ValueError'>: unsupported format character 'p' (0x70) at
<br>> index 5<br>><br>> What is strange is the line Constants.istrBy = '%(1) por %(2)'<br>><br>> This string appears to have lost its "s" at the end of the (1) and the (2)<br>> (which we can see were included in the
es.po file above). I am not sure how<br>> this would have happened, but it does seem to make some sense of the error<br>> (the p character being the first thing interpreted after where an s was<br>> expected.<br>
><br>> Any ideas on where we're doing something wrong? Thanks.<br>><br>> Erik<br>> _______________________________________________<br>> Sugar mailing list<br>> <a href="mailto:Sugar@lists.laptop.org">
Sugar@lists.laptop.org</a><br>> <a href="http://lists.laptop.org/listinfo/sugar">http://lists.laptop.org/listinfo/sugar</a><br>><br>><br><br><br><br>--<br>Walter Bender<br>One Laptop per Child<br><a href="http://laptop.org">
http://laptop.org</a><br></blockquote></div><br>