empty po files

Erik Blankinship erikb at mediamods.com
Wed Feb 6 08:38:05 EST 2008


On 2/6/08, Jani Monoses <jani at ubuntu.com> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.laptop.org/pipermail/devel/attachments/20080206/25d91aa6/attachment.html>


More information about the Devel mailing list