doc/reference/libpurple/plugin_i18n.md

changeset 41164
d861b10105fb
parent 40962
19e53c9cab73
child 41165
24e2c88a7fc2
equal deleted inserted replaced
41161:91c9fc1f1db3 41164:d861b10105fb
1 Title: Third Party Plugin Translation
2 Slug: 3rd-party-plugin-i18n
3
4 ## Third Party Plugin Translation
5
6 ### Introduction
7
8 For the purpose of this document we're going to assume that your plugin:
9
10 * Is set up to use autotools. It may be possible to add translation support
11 without autotools, but we have no idea how. We may not want to know, either ;)
12 * Has an autogen.sh. You may have also called this bootstrap.sh or similar.
13 * Resides in a source tree that has `configure.ac` and `Makefile.am` in the
14 top-level directory as well as a `src` directory in which the plugin's source
15 is located. A `Makefile.am` should also exist in the `src` directory.
16
17 ### Steps To Follow
18
19 For a plugin to have translation support there are a few steps that need to
20 followed:
21
22 * In your `autogen.sh`, add the following after your other utility checks:
23
24 ```sh
25 (intltoolize --version) < /dev/null > /dev/null 2>&1 || {
26 echo;
27 echo "You must have intltool installed to compile <YOUR PLUGIN NAME>";
28 echo;
29 exit;
30 }
31 ```
32
33 * Then before your call to aclocal add:
34
35 ```sh
36 intltoolize --force --copy
37 ```
38
39 * Now edit `configure.ac` and add the following:
40
41 ```m4
42 AC_PROG_INTLTOOL
43
44 GETTEXT_PACKAGE=<YOUR PLUGIN NAME>
45 AC_SUBST(GETTEXT_PACKAGE)
46 AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE, ["$GETTEXT_PACKAGE"], [Define the gettext package to be used])
47
48 ALL_LINGUAS=""
49 AM_GLIB_GNU_GETTEXT
50 ```
51
52 The position of these macros in the file don't really matter, but if you
53 have issues either play around with it or feel free to ask one of the Pidgin
54 developers. Finally add `po/Makefile.in` to you `AC_OUTPUT` command.
55
56 * Now create a directory named 'po'.
57
58 * `cd` into the `po` directory.
59
60 * Create/edit the file `POTFILES.in` in your favorite editor. Each line
61 should be the name of a file that could or does have strings marked for
62 translating (we're getting to that step). These file names should be
63 relative to the top directory of your plugin's source tree.
64
65 * `cd` back to the top directory of your plugin's source tree.
66
67 * Open `Makefile.am` and add `po` to your `SUBDIRS` variable.
68
69 * While still in the top directory of your plugin's source tree, execute
70 `intltool-prepare`. This will setup anything extra that intltool needs.
71
72 * Fire off `autogen.sh` and when it's completed, verify that you have a
73 `po/POTFILES` (notice the lack of a .in). If you do, everything should be
74 set on the autotools side.
75
76 * Take a break, stretch your legs, smoke a cigarette, whatever, because
77 we're done with the autotools part.
78
79 * When you're ready, `cd` into the directory with the source files for your
80 plugin.
81
82 * Open the file containing the `plugin_query` function.
83
84 * If you're not already, please make sure that you are including the
85 `config.h` file for you plugin. Note that `config.h` could be whatever
86 you told autohead to use with AM_CONFIG_HEADER. Also add the following:
87
88 ```c
89 #include <glib/gi18n-lib.h>
90 ```
91
92 Make sure that this include is after you include of your `config.h`,
93 otherwise you will break your build. Also note that if you wish to
94 maintain compatibility with older versions of GLib, you will need to
95 include additional preprocessor directives, which we won't cover here.
96
97 * This is where things get a bit goofy. libpurple is going to try to
98 translate our strings using the libpurple gettext package. So we have to
99 convert them before libpurple attempts to.
100
101 * To do this, we're going to change the entries for `name`, `summary`, and
102 `description` to `NULL`.
103
104 * Next, locate your `plugin_load` function. Your name for this function will be
105 the first parameter to `GPLUGIN_NATIVE_PLUGIN_DECLARE()` plus `_load`.
106
107 * Now add the following within your 'plugin_load' function:
108
109 ```c
110 bindtextdomain(GETTEXT_PACKAGE, PURPLE_LOCALEDIR);
111 bind_textdomain_codeset(GETTEXT_PACKAGE, "UTF-8");
112
113 info.name = _("<YOUR PLUGIN NAME>");
114 info.summary = _("<YOUR PLUGIN SUMMARY>");
115 info.description = _("<YOUR PLUGIN DESCRIPTION>");
116 ```
117
118 > Note that the `_()` is intentional, and that it is telling intltool that
119 > this string should be translated. There is also `N_()` which says that a
120 > string should only be marked for translation but should not be translated
121 > yet.
122
123 * Go through the rest of your code and mark all the other strings for
124 translation with `_()`.
125
126 * When thats done, feel free to commit your work, create your po template
127 (pot file) or whatever.
128
129 * To create you po template, `cd` to `po` and execute:
130
131 ```sh
132 intltool-update --pot
133 ```
134
135 * To add new translations to your plugin, all you have to do is add the
136 language code to the `ALL_LINGUAS` variable in your `configure.ac`. Take
137 note that this list of languages should be separated by a space. After
138 you have added the language code to `ALL_LINGUAS`, drop the `xx.po` file
139 into `po`, and re-`autogen.sh`. After a full build you should now be
140 able to use the translation.

mercurial