[Sugar-devel] forcing a specific language translation

Erik Blankinship erikb at mediamods.com
Sat Dec 10 10:56:13 EST 2011


*Here is a solution. *

import gettext
import os

#I suppose we ought use the activity directory here
force_lang = gettext.translation('SwedishChef',
localedir=os.path.join(os.getcwd(), 'locale'), languages=['sv'] )
force_lang.install( )

def _( s ):

    return force_lang.gettext( s )



On Wed, Dec 7, 2011 at 2:09 PM, Erik Blankinship <erikb at mediamods.com>wrote:

> Normally, I use something like this to automatically get translations from the right .mo file
>
> from gettext import gettext
>
> def _( s ):
>
>     return gettext( s )
>
> But what if I want to force my activity to run in a different language?  (e.g. Swedish Chef Cookbook Activity)
>
> I tried this:
>
> import gettext
>
> force_lang = gettext.translation('SwedishChef', languages=['sv'] )
>
> force_lang.install( )
>
> def _( s ):
>
>     return force_lang.gettext( s )
>
> But it did not work and I get back the default strings from my python code instead.
>
> Any suggestions?  Thanks!
>
> Erik
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.sugarlabs.org/archive/sugar-devel/attachments/20111210/4d4baa2f/attachment-0001.html>


More information about the Sugar-devel mailing list