views:

854

answers:

6

Hello -

I'm currently writing an app in Python and need to provide localization for it.

I can use gettext and the utilities that come with it to generate .po and .mo files. But editing the .po files for each language, one-by-one, seems a bit tedious. Then, creating directories for each language and generating the .mo files, one-by-one, seems like overkill. The end result being something like:

/en_US/LC_MESSAGES/en_US.mo
/en_CA/LC_MESSAGES/en_CA.mo
etc.

I could be wrong, but it seems like there's got to be a better way to do this. Does anyone have any tools, tricks or general knowledge that I haven't found yet?

Thanks in advance!

EDIT: To be a little more clear, I'm looking for something that speeds up the process. since it's already pretty easy. For example, in .NET, I can generate all of the strings that need to be translated into an excel file. Then, translators can fill out the excel file and add columns for each language. Then, I can use xls2resx to generate the language resource files. Is there anything like that for gettext? I realize I could write a script to create and read from a csv and generate the files -- I was just hoping there is something already made.

+2  A: 

It eludes me how you want to achieve a real translation without editing the .po files for each language? Magic?

Edit (after comment) - how to automate the generation of the .po files:

I don't use Gettext, but from the wiki page it looks like you only have to call

msginit --locale=xx --input=name.pot

for every language you want to support. I would generate a script that generates all the language files, give them to the translators, and when you get them back run msgfmt on them.

lothar
Obviously, I want the .po files to be edited, but opening them up one by one is an incredible waste of time. Isn't there a way to define ALL of the languages and translations in a spreadsheet or something, then have the .po files generated?
landyman
A: 

I'm using poEdit for translations.

raspi
A: 

Use scripts. Assume your source code is in the directory $SRC, so create directory $SRC/po for i18n files (pot, po, mo etc). Then create file $SRC/po/POTFILES.in where specify path to source code files with gettext function calls. It may look like:

[encoding: UTF-8]
./main.cpp
./plugins/list.cpp

Now you can use the following commands (inside directory $SRC):

For updating master-file messages.pot:

intltool-update --pot --gettext-package=messages --verbose

For merging changes from messages.pot to fr.po file, for example:

msgmerge -U fr.po messages.pot

To generate mo file use command:

msgmerge -o - fr.po messages.pot | msgfmt -c -o fr/LC_MESSAGES/programname.mo -

Of course directory fr/LC_MESSAGES/ must be created before that call, you can also delete existing fr/LC_MESSAGES/programname.mo before execution

In order to speed up process place all such commands into the corresponding .sh-files for example.

Sergei Stolyarov
A: 

You can try Translate Toolkit for various po file conversions(po2csv for example). Child projects Pootle allows to manage translations over the web.

maciejka
A: 

My suggestion is django-rosetta, which gives you a web based interface to editing your translations. Django doesn't need to be involved at all with your app, you're just using it for an online .PO edit facility.

Another interesting new translation site, which I believe was built using Django/Pinax is Transifex, although I'm not sure if it allows direct editing of the .PO files.

Van Gale
+1  A: 

I've just done this for a project I'm working on, for us the process is like this:

First, I have a POTFILES.in file which contains a list of source files needing translation. We actually have two files (e.g. admin.in and user.in), as the admin interface doesn't always need translating. So we can send translators only the file containing strings the users see.

Running the following command will create a .pot template from the POTFILES.in:

xgettext --files-from=POTFILES.in --directory=.. --output=messages.pot

Run the above command from the po/ directory, which should be a subdirectory of your project and contain the POTFILES.in file. The .pot file has the exact same format as a .po file, but it is a template containing no translations. You create a new template whenever new translatable strings have been added to your source files.

To update the already translated .po files and add new strings to them, run:

msgmerge --update --no-fuzzy-matching --backup=off da.po messages.pot

In the above example I disable fuzzy matching, as our strings are a mess and it did more harm than good. I also disabled backup files, as everything is in subversion here. Run the above command for each language, in this case I updated the danish translation.

Finally run msgfmt to create the .mo files from the .po files:

msgfmt nl.po --output-file nl.mo

Ofcourse, you wouldn't want to run this manually everytime, so create some scripts (or preferably one or more Makefiles) to do this for you.

Note that your directory layout is slightly different from my situation, so you will have to adjust output filenames/paths a bit, but the steps should be the same.

warpr