i18n

I've never used i18n in any of my progs. Could someone point me to the way
to use it ?

I got the sample internat, but it is designed for C++ (using gettext). What
is the way to generate .po files from python ? And how to do with xrc
files?

Thank's,

···

--
   Frederic

   http://linux.gbiloba.org

Frederic wrote:

I've never used i18n in any of my progs. Could someone point me to the way to use it ?

I got the sample internat, but it is designed for C++ (using gettext). What is the way to generate .po files from python ?

The same way.

And how to do with xrc files?

The wxrc utility has an option that will cause it to write out a file with gettext compatible strings in it. By default wxXmlResource will try to look up strings in the language catalogs if wxLocale has been initialized.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Frederic,

You might want to do a search in the archives (on I18n, locale and internationalization) for this, there has been some discussion about it over the last few weeks/month.

Attached one message with some sample code, but there is much more on this list.

See you
Werner

Frederic wrote:

gettexttest.zip (5.18 KB)

Attached Message (11.7 KB)

···

I've never used i18n in any of my progs. Could someone point me to the way to use it ?

I got the sample internat, but it is designed for C++ (using gettext). What is the way to generate .po files from python ? And how to do with xrc files?

Thank's,

Frederic wrote:

> I got the sample internat, but it is designed for C++ (using gettext).
> What is the way to generate .po files from python ?

The same way.

But xgettext don't understand python ?!!? And python (wxPython ?) does
not understand _() function...

Please, could someone give me a complete example for wxPython ?

> And how to do with xrc files?

The wxrc utility has an option that will cause it to write out a file
with gettext compatible strings in it. By default wxXmlResource will
try to look up strings in the language catalogs if wxLocale has been
initialized.

I do not have a wxrc utility :o(

···

On Tuesday 21 October 2003 18:15, Robin Dunn wrote:

--
   Frederic

   http://linux.gbiloba.org

Frederic wrote:

Frederic wrote:

I got the sample internat, but it is designed for C++ (using gettext).
What is the way to generate .po files from python ?

The same way.

But xgettext don't understand python ?!!?

But pygettext.py does.

And python (wxPython ?) does not understand _() function...

Functions in Python are just like any other object, just assign _ to be a reference to whatever function you it to what you want it to be. If you want to use Python's gettext module:

  _ = gettext.gettext

If you want to use wxLocale:

  _ = wxGetTranslation

If you want to make the setting be global, then put _ in to the builtins module:

  __builtins__._ = wxGetTranslation

Please, could someone give me a complete example for wxPython ?

And how to do with xrc files?

The wxrc utility has an option that will cause it to write out a file
with gettext compatible strings in it. By default wxXmlResource will
try to look up strings in the language catalogs if wxLocale has been
initialized.

I do not have a wxrc utility :o(

Looks like I forgot to include it in the Win32 Installers. I'll build it again and make it available for download later today.

···

On Tuesday 21 October 2003 18:15, Robin Dunn wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Frederic <linux@gbiloba.org> writes:

But xgettext don't understand python ?!!?

xgettext 0.11 does. I use it for Thuban and it works fine (at least on
GNU/Linux). The older versions also work but produce lots of warnings.

   Bernhard

···

--
Intevation GmbH http://intevation.de/
Sketch http://sketch.sourceforge.net/
Thuban http://thuban.intevation.org/

In Tuesday, October 21, 2003, 2:29:07 PM, Frederic wrote:

Please, could someone give me a complete example for wxPython ?

IMHO it would be great to have the Demo bringing some wx example of a
simple i18n app.

-- Tacão

E. A. Tacão wrote:

In Tuesday, October 21, 2003, 2:29:07 PM, Frederic wrote:

> Please, could someone give me a complete example for wxPython ?

IMHO it would be great to have the Demo bringing some wx example of a
simple i18n app.

Yep, somebody want to write that sample for me?

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Thank you all for your help: I understand a little bit more how things
work. I have some more questions:

1) What is better: python gettext module, or wxLocale ?

2) Once I have generated and translated the .po file, how to proceed if I
modify my code, and have to generate a new .po file without loosing my
previous translations ?

3) What tool do you prefere to translate ? kbabel, gtranslator, or poedit ?

Thank's

PS: Once I understand all i18n stuff, I will try to post a little exemple.

···

On Tuesday 21 October 2003 19:47, Robin Dunn wrote:

> But xgettext don't understand python ?!!?

But pygettext.py does.

> And python (wxPython ?) does
> not understand _() function...

Functions in Python are just like any other object, just assign _ to be
a reference to whatever function you it to what you want it to be. If
you want to use Python's gettext module:

  _ = gettext.gettext

If you want to use wxLocale:

  _ = wxGetTranslation

If you want to make the setting be global, then put _ in to the builtins
module:

  __builtins__._ = wxGetTranslation

--
   Frederic

   http://linux.gbiloba.org

Robin Dunn wrote:

I do not have a wxrc utility :o(

Looks like I forgot to include it in the Win32 Installers. I'll build it again and make it available for download later today.

You can now get wxrc.zip (containing wxrc.exe) from SF:

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Nothing for poor Linux users :o( ?

···

On Tuesday 21 October 2003 21:34, Robin Dunn wrote:

You can now get wxrc.zip (containing wxrc.exe) from SF:

--
   Frederic

   http://linux.gbiloba.org

Frederic wrote:

Thank you all for your help: I understand a little bit more how things work. I have some more questions:

1) What is better: python gettext module, or wxLocale ?

AFAIK, they are roughly equivallent except for two things: XRC and also the localized strings in the wxWindows library will try to use wxLocale, so you may as well just use wxLocale and handle everything in one place.

2) Once I have generated and translated the .po file, how to proceed if I modify my code, and have to generate a new .po file without loosing my previous translations ?

3) What tool do you prefere to translate ? kbabel, gtranslator, or poedit ?

These questions I don't know as much about so I'll let somebody else answer. However, the author of POedit is a member of this list so that may be a factor in your choice.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Frederic wrote:

···

On Tuesday 21 October 2003 21:34, Robin Dunn wrote:

You can now get wxrc.zip (containing wxrc.exe) from SF:

Nothing for poor Linux users :o( ?

It should already be in the RPMs and in the .dmg for OS X.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn <robin@alldunn.com> writes:

E. A. Tacão wrote:

In Tuesday, October 21, 2003, 2:29:07 PM, Frederic wrote:
> Please, could someone give me a complete example for wxPython ?
IMHO it would be great to have the Demo bringing some wx example of a
simple i18n app.

Yep, somebody want to write that sample for me?

IIRC there's already one at the wiki...

···

--
Godoy. <godoy@metalab.unc.edu>

Is it a tool only in 2.4.2.4 version ? I can't find it in the debian
packages (even in the sid, which contains the 2.4.1.2 version).

···

On Tuesday 21 October 2003 21:57, Robin Dunn wrote:

> Nothing for poor Linux users :o( ?

It should already be in the RPMs and in the .dmg for OS X.

--
   Frederic

   http://linux.gbiloba.org

Frederic wrote:

But xgettext don't understand python ?!!?

But pygettext.py does.

I am using GNU xgettext on Win32 and it handles Python just fine.

xgettext -V brings:

xgettext (GNU gettext-tools) 0.12.1
Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Ulrich Drepper.

I created a script that creates the first .pot file from parsing all .py files in a directory, merges the existing .po with the new generated file (makeing a list of any change) and that can create the .mo files from compiling the .po files that are in the directory. If anyone is interested let me know and I'll email it or post it somewhere.

Pierre

···

On Tuesday 21 October 2003 19:47, Robin Dunn wrote:

xgettext (GNU gettext-tools) 0.12.1

I have an older version:

xgettext (GNU gettext) 0.10.40

I created a script that creates the first .pot file from parsing all .py
files in a directory, merges the existing .po with the new generated
file (makeing a list of any change) and that can create the .mo files
from compiling the .po files that are in the directory. If anyone is
interested let me know and I'll email it or post it somewhere.

Yes please !!! I tried to use POedit, and it works very well. But I would
like to understand what it does exactly. I think reading your script will
help me...

···

On Wednesday 22 October 2003 03:40, Pierre Rouleau wrote:

--
   Frederic

   http://linux.gbiloba.org

Frederic wrote:

xgettext (GNU gettext-tools) 0.12.1

I have an older version:

xgettext (GNU gettext) 0.10.40

I created a script that creates the first .pot file from parsing all .py
files in a directory, merges the existing .po with the new generated
file (makeing a list of any change) and that can create the .mo files
from compiling the .po files that are in the directory. If anyone is
interested let me know and I'll email it or post it somewhere.

Yes please !!! I tried to use POedit, and it works very well. But I would like to understand what it does exactly. I think reading your script will help me...

POedit helps you edit .po (Portable Object) files. A .po file is a text file that contains the list of :

  - msgid: original (English) strings extracted from the scanned source
  - msgstr: the translated string

I myself, normally use my day-to-day editor (CRiSP) to translate all strings. I copy the generated .pot file into the .po file then edit it to translate each msgid: I write the translated copy just below after the 'msgstr' keyword.

For example, I wrote an application called ivcm. All strings that must be internationalized inside ivcm.py (and its companion files) have the form _("Hello"). All strings inside the source code *must* be in English as this is the convention used by the gettext system.

To use my mki18n.py script, I write a file called app.fil that contains the names of all files inside the application (one file per line, with full or relative path. For example:

images.py
ivcm.py
ivcm_about.py
ivcm_ie.py
ivcm_usermanual.py
ivcm_wxFrame1.py
../ptz.py
../action.py
../utprint.py

Then I run 'mki18n -p' from the directory where ivcm.py is located to parse all source files and create a 'messages.pot' file. The .pot is the original template. You keep this file untouched. If I want to support French then I copy the messages.pot into a .po file named after the domain name (in this case the application name: 'ivcm') and the target language code (in this case: 'fr'). So for French I use the file name: ivcm_fr.po. If I need to support Spanish, I copy messages.pot into ivcm_sp.po and so on.

The following lines show a couple of entries inside the non translated ivcm_fr.po:

#: ivcm.py:168
#, python-format
msgid ""
"\n"
" ERROR: %s"
msgstr ""

#: ivcm_wxFrame1.py:638 ivcm_wxFrame1.py:1742
msgid "&About..."
msgstr ""

The next step is to perform the translation. You can use a normal editor to append the French string inside the ivcm_fr.po or use poEdit or any other .po editor. The result of the translation would look like:

#: ivcm.py:168
#, python-format
msgid ""
"\n"
" ERROR: %s"
msgstr ""
"\n"
" ERREUR: %s"

#: ivcm_wxFrame1.py:638 ivcm_wxFrame1.py:1742
msgid "&About..."
msgstr "À propos de iVCM..."

Note that every line with a '#' in the first column is a comment or flag. In the example above the python-format flag shows that the strings were extracted from Python source. The #: lines show the line number of the original source.

Some of the flags are set when you re-synchronyze the translations with the source. This resynchronization is required if the source changes after you have created the translated .po file(s).

My mki18n.py script will automatically perform syncronisation if it finds .po files that have the domain_language.po name layout. After a re-synchronization, 'mki18n -p' creates a .new file for every .po file found. In my example, it would create a ivcm_fr.po.new and a ivcm_sp.po.new

If the source has not changed, the .new files are equal to the .po file. Otherwise, the .new file contains the new strings to translate, place the straing that were removed from the source as comments inside the .po.new file and may also flag some strings as 'fuzzy'. A fuzzy flag indicates that the translation of the original source should probably change because the original string changed. So, I compare the .po and .po.new, and edit whatever is requiered, leaving the finished work inside the .po file.

The final step is to compile the finished .po file into the .mo file.

The .mo file normally reside inside the LC_MESSAGES of a 'locale' sub-directory with a xx/LC_MESSAGES for each supported language:

du locale
          3 locale/en/LC_MESSAGES
       8803 locale/en
        172 locale/fr/LC_MESSAGES
       7997 locale/fr
          4 locale/sp/LC_MESSAGES
         54 locale/sp
      20413 locale

I create the .mo file using 'mki18n -m' which uses the msgfmt.exe tool that comes with the GNU gettext utility.

And then the application uses the .mo file!

I will email you the application directly (along with a HTML file on the i18n topic i wrote with reStructuredText). If anyone else is interested in the list, ask me and I'll gladly send it too. If there is a spot to put such things, let me know.

Pierre

···

On Wednesday 22 October 2003 03:40, Pierre Rouleau wrote:

Frederic wrote:

···

On Tuesday 21 October 2003 21:57, Robin Dunn wrote:

Nothing for poor Linux users :o( ?

It should already be in the RPMs and in the .dmg for OS X.

Is it a tool only in 2.4.2.4 version ? I can't find it in the debian packages (even in the sid, which contains the 2.4.1.2 version).

It may not be in the deb's. I've mentioned it to the package maintainer
as he is about to do the 2.4.2.4 builds.

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Pierre Rouleau wrote:

I created a script that creates the first .pot file from parsing all .py files in a directory, merges the existing .po with the new generated file (makeing a list of any change) and that can create the .mo files from compiling the .po files that are in the directory. If anyone is interested let me know and I'll email it or post it somewhere.

The wiki would be a good place for it. After the i18n questions that
have come up lately it is clear that having a few cookbook entries about
it would be nice to have. I've added a new category for it: http://wiki.wxpython.org/index.cgi/RecipesInternationaliazation

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!