Recycling old translations

Last modified: October 17, 2008 - 20:56

Drupal users with existing translations might want to add those to the translations download page. To do this they first need to export their translation from the localization manage languages screen (export sub-tab). Let us assume you have an Italian translation. The above mentioned process will create an it.po file for you. To use this file as a basis for a new translation, you treat it as a PO compendium, i.e. a library of pre-translated strings.

This guide assumes a Unix/Linux environment. If you use Windows, check if your PO editor doesn't have a function for this.

We will split the single, large PO file into the smaller files that the Drupal translation Project requires.

First, put the small POT files into a sub-directory drupal-pot and your it.po file into another one. Then create an empty directory where you want to keep your new small PO files.

Then go to the empty directory and execute the following command from the command line:

for i in /path/to/drupal-pot/*.pot ; do msgmerge  --compendium /path/to/it.po -o `basename $i .pot`.po /dev/null $i  ; done

After a while (yes this will take a few minutes) you should have a directory of small PO files that have the matching strings inserted.

You can also do without compendium with this:

for i in *.po; do msgmerge  --update $i ../drupal-pot/${i}t ; done

This will update all .po files in current directory with appropriate file from ../drupal-pot/ directory. This is useful when updating for example from 4.6.1 to 4.6.2 (when there is small number of changes).

Partial translations
Let's say you have partially translated .po files for modules and someone sends you a LANG.po file which contains strings s/he translated himself.

You can merge translations using following approach:
0. Of course you already have a backup of your files :)
1. You need .pot files for all of your .po files you want to update, let's say they are in ../POTS dir
2. Concatenate .po files you want to update with LANG.po file:

msgcat -o ../update.po LANG.po file1.po file2.po ... fileN.po

3. Fix update.po's header, it'll be written into update .po files
4. The best is to check update.po with msgfmt and fix any errors:
msgfmt -o /dev/null -c --statistics ../update.po

5. Update .po files (this will update all .po files in current dir):
for i in *.po; do msgmerge -o $i ../update.po ../POTS/${i}t; done

6. Remove obsolete translations:
for i in *.po; do msgattrib -o $i.no-o  --no-obsolete $i && mv $i.no-o $i; done

You should have your .po files updated. Now you need fix fuzzy entries and check translation for consistency. If a string was translated both in the LANG.po file you were sent and in your own .po file then both translations will be included in the updated .po file. You need to check it and decide which one is better.

 
 

Drupal is a registered trademark of Dries Buytaert.