Translations

To make your application translatable, you must use i18n() in the code, around the English strings that appear to the user. You must also define a messages target in your toplevel Makefile.am. A script runs every night, and calls all messages targets as they are, to create the .pot files that end up in the kde-i18n module. Then translators can create .po files that contain the translations of those messages.

For applications not in SVN, run

make -f admin/Makefile.common package-messages
to generate the .pot file, and
make merge
for the message merge (new .pot file with old .po file). IMPORTANT: you need to use a patched gettext, available from ftp.kde.org, for proper support of contextual translations and plural handling.

Let's now go back to the messages target. It should simply call xgettext on the sources that contain i18n - which is not equal to _SOURCES, as _SOURCES contains .ui and .skel files that do not work with xgettext. This is why you usually use something like *.cpp *.h instead (make sure to include sub-directories, if any). So in the simple case a messages target will look like:

messages:
	$(XGETTEXT) *.cpp *.h -o $(podir)/mypotfile.pot

Note: the second line must begin with a tabulator, as it is part of the Makefile syntax (the same with any further line needed).

Note 2: the name of the .pot file must be unique across KDE, so better use an application name or module name as prefix, like for example kofficefilters.pot.

mypotfile is the name of your main KInstance (for an application it's the first argument passed to KAboutData, and for components (parts and plugins), it's the name of the KInstance that you create).

If you have .ui (Qt designer), .rc (XML-UI) or .kcfg files, use messages: rc.cpp and the script will create rc.cpp from the ui and rc files in the current directory. If you have .ui, .rc or *.kcfg files in subdirectories, you need to add something like

messages: rc.cpp
and the script will create rc.cpp from the ui and rc files in the current directory. If you have .ui, .rc or *.kcfg files in subdirectories, you need to add something like
$(EXTRACTRC) */*.rc >> rc.cpp
to the messages target, before the xgettext call.

Another special case is the "tips" file - an XML file containing tips shown to the user. In this case, use something like

messages:
	perl ./preparetips > tips.cc
	$(XGETTEXT) *.cpp *.h tips.cc -o $(podir)/mypotfile.pit
	rm -f tips.cc

You can find the preparetips script under kdebase/ktip, for instance. (The name of the temporary tips.cc file doesn't matter, obviously).

The last matter is the compilation and installation of .po files. Inside kde-i18n, Makefile.am files contain

KDE_LANG = language
and
POFILES = AUTO
to mean that all the .po files in the directory are installed into that language.

If you ship a separate application and you want it to install its own .po files, you'll usually have a po/ subdirectory, and inside the Makefile.am will simply say

POFILES = AUTO
. In that case, the .po files are copied depending on their name as $(PACKAGE).mo (for instance de.po is installed under de/LC_MESSAGES/$(PACKAGE).mo and fr.po into fr/LC_MESSAGES/$(PACKAGE).mo).