[Tutor] Simple way for i18n ?

francois schnell francois.schnell at gmail.com
Sat Mar 25 10:47:51 CET 2006


Hello Micheal,

I've  changed LANGUAGE in the shell , it worked at the beginning and then it
stopped working ...
Also os.environ.setdefault method still has no effect. I begin to wonder if
it's specific to my distro (Ubuntu Breezy).

Anyway I managed to use "translation" but if I give None for languages (or
nothing) he gives back an IOError.

I'm finaly using a mix of "install" and "translation" through an exception
handling and I can also change the language on the fly in the app.
It works but it's probably not very "academic"  :)
http://www.flickr.com/photos/frenchy/117229913/

Thanks
francois

On 24/03/06, Michael Lange <klappnase at freenet.de> wrote:
>
> On Thu, 23 Mar 2006 23:58:58 +0100
> "francois schnell" <francois.schnell at gmail.com> wrote:
>
> >
> > Now I'd like to be able to change language without loging out, change
> > language, log in.
> >
> > Martelli says in his book that to set the default language for the app I
> > just need to do:
> >
> > >>> os.environ.setdefault('LANG', 'fr_FR')
> >
> > and Python doesn't complain (but doesn't work) but if I then do:
> >
> > >>> print locale.getdefaultlocale()
> >
> > Python says : ('en_GB', 'utf-8')  # meaning that really couldn't work ?
> >
> > How can I have my app in French even if I'm still in the GB version of
> > Ubuntu (change the language for the app) ?
> >
>
> Hi Francois,
>
> I tried to do so with one of my apps (on Mandrake) and found that I have
> to change
> the LANGUAGE environment variable, changing LANG had no effect on this.
> >From the python gettext docs I found:
>
>     If languages is not given, then the following environment variables
> are searched: LANGUAGE, LC_ALL, LC_MESSAGES, and LANG.
>
> So it looks like the easiest may be to do
>
>     $ LANGUAGE=en_GB
>
> in the shell before you start your app.
>
> > I've also tried the "translation" way instead of the "install" way:
> >
> > if I do:
> > gettext.install("myapp", localedir) #it translates in French when I'm in
> the
> > French Ubuntu
> > but if I do instead: gettext.translation("myapp", localedir,
> > languages="fr_FR") #with the same localedir which worked before
> > =>
> > Python complains:
> > "    gettext.translation("myapp", localedir, languages="fr_FR")
> >   File "/usr/lib/python2.4/gettext.py", line 480, in translation
> >     raise IOError(ENOENT, 'No translation file found for domain',
> domain)
> > IOError: [Errno 2] No translation file found for domain: 'myapp' "
> >
> > I find it strange that "install" finds it but not "translation" (for the
> > same localedir) ?
> >
>
> I admit I nevered bothered to find out how to use gettext.translation()
> since gettext.install()
> works that fine for me. Maybe you should set "languages" to "fr" instead
> of "fr_FR" (just a guess though)?
>
> I hope this helps
>
> Michael
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20060325/30e81b0f/attachment.htm 


More information about the Tutor mailing list