On 2/6/08, Jani Monoses <[EMAIL PROTECTED]> wrote:
>
> Hello,
>
> building the calculate activity for Ubuntu I noticed it failed because
> the th.po file is empty. Reported here
> http://dev.laptop.org/ticket/6357
>
> Is there something in the software that does the automated imports of
> translations, that can prevent this from happening in general?



We ran into problems with some.po files whose translations modified
variables in strings (making them unparsable).
The solution we came up with serves two functions:

   1. it is compatible with setup.py genpot (since we use _
   2. protects against unparsable translations / prevents crashes

If unable to parse the string, we default back to the original language (not
optimal, but better than crashing).

Here's some code:

from gettext import gettext as gt

        #defensive method against variables not translated correctly
        def _(s):
                #todo: permanent variable
                istrsTest = {}
                for i in range (0,4):
                        istrsTest[str(i)] = str(i)


                i = s
                try:
                        #test translating the string with many replacements
                        i = gt(s)
                        test = i % istrsTest
                except:
                        #if it doesn't work, revert
                        i = s

                return i


Use the returned value from this method when you need internationalized
strings in your app.
_______________________________________________
Devel mailing list
Devel@lists.laptop.org
http://lists.laptop.org/listinfo/devel

Reply via email to