Internationalization
The first step in localization (“l10n”) is internationalization (“i18n”). One of the i18n tasks is the separation of code and messages. WordPress chose gettext as the primary means to do so.
Gettext
If the plugin does not yet contain gettext functions, the first step is to add them:
- Add
load_plugin_textdomain(domain, path)to the top of your plugin. “domain” is usually the name or the plugin and "path" is the basename of the mo file. The default for “path” is “wp-content/plugins” - wrap every string of a plugin with
__()or_e(). The first one simply returns the text as function result, while the second one echoes it.
pot File
If the plugin does not yet come with a pot (po template) file, create
one by extracting all occurrences of __() and _e()
from the plugin:
xgettext --keyword=__ --keyword=_e --default-domain=your_plugin
--language=php your_plugin.php --output=your_plugin.pot
po File
That's where i18n ends and l10n starts. Create a language specific po file from the international po template (“pot”) by simply copying it:
cp your_plugin.pot your_plugin-your_language.po
Now use either a plain vanilla text editor or poedit to add your
translations to that file.
mo File
Finally compile the ASCII po file to a binary mo file:
msgfmt -o your_plugin-your_language.mo
your_plugin-your_language.po
Done
I did the internationalization for wp-wap and added to the localization of wp-mobile. I created a german po file for both.
