Skip to content

Translation

John Cupitt edited this page Mar 29, 2017 · 1 revision

title: Translation permalink: /Translation/

The VIPS library and nip2 program use gettext to translate messages for display. The GNOME project has a handy translation HOWTO. Internationalising GNOME applications has a lot of detail.

These instructions will create a new translation. Updating an existing one is easier: just edit nip2-7.11.x/po/en_GB.po to update the British English version, for example.

Create the .po file

You need the full and latest source code for this. Go to the Development page and follow the instructions there.

Files relating to translation are all inside nip2-7.11.x/po. The file nip2-7.11.x/po/POTFILES.in lists all the source code files which should be scanned for translatable strings: you may need to update it.

Run intltool to extract strings for translation.

cd nip2-7.11/po intltool-update --pot

This will generate nip2.pot, a sample translation file.

Copy this file to make your new .po file ready for translation. The file name should be your country code: it.po for Italian, for example. We'll use "test" here.

cp nip2.pot test.po

Edit the file

Edit in vim (or equivalent) to fix up the header and put in some sample translations. These search and replace operations will swap every msgstr string for the word Malkovich.

:%s/msgstr ""/msgstr "Malkovich"/ :%s/msgstr 0  ""/msgstr[0] "Malkovich"/ :%s/msgstr 1  ""/msgstr[1] "Malkovich"/ :g/#, c-format/d

Remove the boilerplate header from intltool and put this test header at the start of the file:

# test translation file
#
msgid ""
msgstr ""
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"Project-Id-Version: nip2 7.11.11\n"
"POT-Creation-Date: 2006-09-06 12:18+0000\n"
"PO-Revision-Date: 2006-09-06 12:30+0000\n"
"Last-Translator: john <jcupitt@gmail.com>\n"
"Language-Team: dk <LL@li.org>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"

You can check your .po file for errors:

msgfmt -cv -o /dev/null test.po

Adding to the build system

The build system needs to know to compile and install your translation. Edit nip2-7.11.x/configure.in and add the name of your translation to the end of the ALL_LINGUAS line, for example:

ALL_LINGUAS="en_GB malkovich test"

Now rebuild the build system:

cd nip2-7.11.x ./bootstrap.sh

And configure, make, install as usual:

./configure --prefix=/some/test/install/area make make install

Testing the translation

Set the environment variable LANGUAGE and run nip.

export LANGUAGE=test nip2

And you should see your translations.

Caveats

This will only translate messages in the nip2 C source code. You need a separate system to extract messages from nip2's macros. Try:

nip2 --i18n

to print all the macro messages to stdout. You need to incorporate those as well. And not all of nip2's macros have been marked up for translation, so it won't be perfect.

Also, this will not translate messages produced by libvips. You need to work on vips-7.11.x/po separately for that.

Adding your translation to the distribution

Mail your finished .po file to one of the maintainers and get them to add it to CVS. Thank you very much for your work!

Clone this wiki locally