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: