Thanks both for your help,<br>
<br>
I managed to find one book which talk about i18n for Python: "Python in a Nutshell" (few pages for i18n)<br>
<br>
I've used sys.prefix on my ubuntu box to find the default directory and it works fine this way:<br>
<a href="http://www.flickr.com/photos/frenchy/116742621/">http://www.flickr.com/photos/frenchy/116742621/</a><br>
<br>
I've also done like you said:<br>
gettext.install(domain, localedir)<br>
and now it works fine also with a locale directory :)<br>
<br>
Then what I've got now is:<br>
- I log on the french version of Ubuntu I've got the french app version<br>
- I log on the UK version of Ubuntu I've got the original app version in English<br>
<br>
Now I'd like to be able to change language without loging out, change language, log in.<br>
<br>
Martelli says in his book that to set the default language for the app I just need to do:<br>
<br>
>>> os.environ.setdefault('LANG', 'fr_FR')<br>
<br>
and Python doesn't complain (but doesn't work) but if I then do:<br>
<br>
>>> print locale.getdefaultlocale()<br>
<br>
Python says : ('en_GB', 'utf-8') # meaning that really couldn't work ?<br>
<br>
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) ?<br>
<br>
I've also tried the "translation" way instead of the "install" way:<br>
<br>
if I do:<br>
gettext.install("myapp", localedir) #it translates in French when I'm in the French Ubuntu<br>
but if I do instead: gettext.translation("myapp", localedir, languages="fr_FR") #with the same localedir which worked before<br>
=><br>
Python complains:<br>
" gettext.translation("myapp", localedir, languages="fr_FR")<br>
File "/usr/lib/python2.4/gettext.py", line 480, in translation<br>
raise IOError(ENOENT, 'No translation file found for domain', domain)<br>
IOError: [Errno 2] No translation file found for domain: 'myapp' "<br>
<br>
I find it strange that "install" finds it but not "translation" (for the same localedir) ?<br>
<br>
Thanks in advance If you can help.<br>
<br>
francois<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br><br><div><span class="gmail_quote">On 23/03/06, <b class="gmail_sendername">Michael Lange</b> <<a href="mailto:klappnase@freenet.de">klappnase@freenet.de</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;">
On Wed, 22 Mar 2006 17:41:14 +0100<br>"francois schnell" <<a href="mailto:francois.schnell@gmail.com">francois.schnell@gmail.com</a>> wrote:<br><br>> Hello all,<br>><br>> I wish to translate a Python script from English to French. I've read the
<br>> offical documentation (<a href="http://python.org">python.org</a> doc) but I must admit that I'm lost now<br>> ...<br>> I've found some simple explanations here but I can't make it work:<br>> <a href="http://karrigell.sourceforge.net/en/internationalization.htm">
http://karrigell.sourceforge.net/en/internationalization.htm</a><br>><br>> Here's where I'm stuck:<br>><br>> Let's imagine my app is: myapp.py<br>> --<br>> import gettext<br>> _ = gettext.gettext<br>>
<br>> print _("hello friends")<br>> print _("Bye Bye")<br>> ---<br>><br>> Here are my folders on a windows box:<br>><br>> C:\myappfolder\<br>> -----------------------\Translations\francais\LC_MESSAGES
<br>><br>> My myapp.py is in myappfolder<br>><br>> In this folder I've used pygettext.py to produce a messages.pot file => I<br>> add the translation in it => I have a messages.po file.<br>> I then used
msgfmt.py to produce messages.mo file.<br>><br>> I then copied messages.po and messages.mo in LC_MESSAGES folder<br>> C:\myappfolder\<br>> -----------------------\Translations\francais\LC_MESSAGES<br>><br>> I now come back to
myapp.py and add two lines:<br>><br>> ---<br>> import gettext<br>> _ = gettext.gettext<br>><br>> t=gettext.translation("messages","c:\myappfolder\Translations","francais")<br>
> t.install()<br>><br>> print _("hello friends")<br>> print _("Bye Bye")<br>> ---<br>><br>> When I do that Python anwers:<br>><br>> >>><br>> Traceback (most recent call last):
<br>> File "C:\myappfolder\myapp.py", line 4, in ?<br>> t=gettext.translation<br>> ("messages","c:\myappfolder\Translations","francais")<br>> File "C:\Python24\lib\gettext.py", line 456, in translation
<br>> raise IOError(ENOENT, 'No translation file found for domain', domain)<br>> IOError: [Errno 2] No translation file found for domain: 'messages'<br>> >>><br>><br>Hi Francois,<br><br>not sure if it is different on windows, on linux I simply do:
<br><br> import gettext<br> gettext.install(domain, localedir)<br><br>to install _() into my application's global namespace,<br>where localedir in your case was "c:\myappfolder\Translations".<br>The path that contains the french translation should be "..\fr\LC_MESSAGES" instead of "..\francais\LC_MESSAGES"
<br>I think (at least that is true on linux).<br><br>I hope this helps<br><br>Michael<br><br>_______________________________________________<br>Tutor maillist - <a href="mailto:Tutor@python.org">Tutor@python.org</a><br>
<a href="http://mail.python.org/mailman/listinfo/tutor">http://mail.python.org/mailman/listinfo/tutor</a><br></blockquote></div><br>