1 <?xml version='1.0' encoding="ISO-8859-1"?>
2 <!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
3 "http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" [
5 <chapter id="chapter-plugin-i18n">
6 <title>Third Party Plugin Translation</title>
8 <sect2 id="plugin-i18n-introduction">
9 <title>Introduction</title>
12 For the purpose of this document we're going to assume that your plugin:
16 Is set up to use autotools. It may be possible to add translation support
17 without autotools, but we have no idea how. We may not want to know, either ;)
20 Has an autogen.sh. You may have also called this bootstrap.sh or similar.
23 Resides in a source tree that has <literal>configure.ac</literal> and
24 <literal>Makefile.am</literal> in the top-level directory as well as a
25 <literal>src</literal> directory in which the plugin's source is located. A
26 <literal>Makefile.am</literal> should also exist in the <literal>src</literal>
33 <sect2 id="plugin-i18n-steps">
34 <title>Steps to follow</title>
37 For a plugin to have translation support there are a few steps that need to
42 In your autogen.sh, add the following after your other utility checks:
44 (intltoolize --version) < /dev/null > /dev/null 2>&1 || {
46 echo "You must have intltool installed to compile <YOUR PLUGIN NAME>";
51 Then before your call to aclocal add:
53 intltoolize --force --copy
57 Now edit configure.ac and add the following:
61 GETTEXT_PACKAGE=<YOUR PLUGIN NAME>
62 AC_SUBST(GETTEXT_PACKAGE)
63 AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, ["$GETTEXT_PACKAGE"], [Define the gettext package to be used])
68 The position of these macros in the file don't really matter, but if you
69 have issues either play around with it or feel free to ask one of the Pidgin
70 developers. Finally add 'po/Makefile.in' to you 'AC_OUTPUT' command.
73 Now create a directory named 'po'.
76 'cd' into the 'po' directory.
79 Create/edit the file 'POTFILE.in' in your favorite editor. Each line
80 should be the name of a file that could or does have strings marked for
81 translating (we're getting to that step). These file names should be
82 relative to the top directory of your plugin's source tree.
85 'cd' back to the top directory of your plugin's source tree.
88 Open 'Makefile.am' and add 'po' to your 'SUBDIRS' variable.
91 While still in the top directory of your plugin's source tree, execute
92 'intltool-prepare'. This will setup anything extra that intltool needs.
95 Fire off 'autogen.sh' and when it's completed, verify that you have a
96 'po/POTFILES' (notice the lack of a .in). If you do, everything should be
97 set on the autotools side.
100 Take a break, stretch your legs, smoke a cigarette, whatever, because
101 we're done with the autotools part.
104 When you're ready, 'cd' into the directory with the source files for your
108 Open the file containing the 'plugin_query' function.
111 If you're not already, please make sure that you are including the
112 'config.h' file for you plugin. Note that 'config.h' could be whatever
113 you told autohead to use with AM_CONFIG_HEADER. Also add the following:
115 #include <glib/gi18n-lib.h>
117 Make sure that this include is after you include of your 'config.h',
118 otherwise you will break your build. Also note that if you wish to
119 maintain compatibility with older versions of GLib, you will need to
120 include additional preprocessor directives, which we won't cover here.
123 This is where things get a bit goofy. libpurple is going to try to
124 translate our strings using the libpurple gettext package. So we have to
125 convert them before libpurple attempts to.
128 To do this, we're going to change the entries for name, summary, and
132 Next, locate your 'plugin_load' function. Your name for this function
133 may vary, but it's the third parameter to 'PURPLE_PLUGIN_INIT'.
136 Now add the following within your 'plugin_load' function:
138 bindtextdomain(GETTEXT_PACKAGE, PURPLE_LOCALEDIR);
139 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
141 info.name = _("<YOUR PLUGIN NAME>");
142 info.summary = _("<YOUR PLUGIN SUMMARY>");
143 info.description = _("<YOUR PLUGIN DESCRIPTION>");
145 Note that the _() is intentional, and that it is telling intltool that
146 this string should be translated. There is also N_() which says that a
147 string should only be marked for translation but should not be translated
151 Go through the rest of your code and mark all the other strings for
152 translation with _().
155 When thats done, feel free to commit your work, create your po template
156 (pot file) or whatever.
159 To create you po template, 'cd' to 'po' and execute:
161 intltool-update --pot
165 To add new translations to your plugin, all you have to do is add the
166 language code to the 'ALL_LINGUAS' variable in your configure.ac. Take
167 note that this list of languages should be separated by a space. After
168 you have added the language code to 'ALL_LINGUAS', drop the xx.po file
169 into 'po', and re-'autogen.sh'. After a full build you should now be
170 able to use the translation.