<br><br><div><span class="gmail_quote">On 2/6/08, <b class="gmail_sendername">Jani Monoses</b> <<a href="mailto:jani@ubuntu.com" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">jani@ubuntu.com</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;">
Hello,<br><br>building the calculate activity for Ubuntu I noticed it failed because<br>the th.po file is empty. Reported here<br><a href="http://dev.laptop.org/ticket/6357" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">http://dev.laptop.org/ticket/6357</a><br>
<br>Is there something in the software that does the automated imports of<br>
translations, that can prevent this from happening in general?</blockquote><div><br><br>We ran into problems with some.po files whose translations modified variables in strings (making them unparsable). <br>The solution we came up with serves two functions:<br>
<ol><li>it is compatible with setup.py genpot (since we use _<br></li><li>protects against unparsable translations / prevents crashes</li></ol>If unable to parse the string, we default back to the original language (not optimal, but better than crashing).<br>
<br>Here's some code:<br><pre>from gettext import gettext as gt</pre><pre> #defensive method against variables not translated correctly<br> def _(s):<br> #todo: permanent variable<br> istrsTest = {}<br> for i in range (0,4):<br>
istrsTest[str(i)] = str(i)<br><br><br> i = s<br> try:<br> #test translating the string with many replacements<br> i = gt(s)<br> test = i % istrsTest<br> except:<br> #if it doesn't work, revert<br> i = s<br>
<br> return i</pre><br></div>Use the returned value from this method when you need internationalized strings in your app.<br>
</div>