Plugins that do not get shipped with b2evolution have to provide their own translations.
Inside your plugin’s directory (e.g.
example_plugin/), create a directory called
locales, where you create a subdirectory and a
_global.php file therein for each locale that is supported:
example_plugin/ locales/ messages.pot de_DE/ LC_MESSAGES/ messages.po _global.php fr_FR/ LC_MESSAGES/ messages.po _global.php ...
Note: The directory structure is the same as what you have below
To help you generate this, b2evo has a ‘'’xg.php”’ script in
/gettext/xg.php. This does not get shipped with releases, but is available from the CVS / SourceForge: http://evocms.cvs.sourceforge.net/evocms/b2evolution/gettext/xg.php?view=markup Get xg.php. You will also need the file
_pofile.class.php in the current directory, which you can get also from the http://evocms.cvs.sourceforge.net/viewvc/evocms/b2evolution/blogs/inc/locales/_pofile.class.php?view=log CVS repository.
The process to create this is:
- First the plugin needs a
messages.pot(PO-template) file. This gets generated whenever some translation strings in the plugin’s source get changed:
mkdir locales/ # if it does not exist yet php -f xg.php CWD extract
- A) Then you’ll need a
messages.pofile for every language (e.g. for ‘’de_DE'’). You’ll have to do the following only to init the
messages.pofile of a language (if there is not already one):
mkdir -p locales/''de_DE''/LC_MESSAGES msginit -i locales/messages.pot -o locales/''de_DE''/LC_MESSAGES/messages.po
- B) If there’s already a
messages.pofile for a locale, you can update it from
messages.pot. The following will update
php -f xg.php CWD merge ''de_DE''
- Edit the
messages.pofile with a normal text editor or tool like poedit or KBabel. You should normally only have to update untranslated or fuzzy strings.
- Convert the
messages.pofile to the final
_global.phpfile. The following command will create a new
php -f xg.php CWD convert ''de_DE''
- Send your updated
_global.phpfiles to the Plugin maintainer (if you are not maintaining it yourself, of course)
Plugins only use the
_global.php file, not the
messages.po files. The messages files are only important to people who want to translate the Plugin.
So, you do not have to package them with your plugin and if your plugin only has very few strings to be translated, you could even skip the whole procedure above and just create the
_global.php files "by hand", in the following way:
<?php $trans[ 'de_DE' ] = array( '' => 'Content-Type: text/plain; charset=ISO-8859-1', 'Hello world!' => 'Hallo Welt!', 'Hello moon!' => 'Hallo Mond!', ... ); ?>
It’s just an array, in fact. But providing the "gettext-Extra-Step" might help your translators a lot, because there are powerful editors for
messages.po files available.
The charset for the localized strings must be supplied in the
$trans['xx_XX'] array inside of the ‘’ (empty) key, which is the default gettext behaviour.
E.g., for de_DE it may look like:
$trans['de_DE'] = array( '' => 'Project-Id-Version: messages Report-Msgid-Bugs-To: http://daniel.hahler.de/ [...] Content-Type: text/plain; charset=ISO-8859-1 [...] X-Generator: KBabel 1.11.2 ', 'Captcha images' => 'Captcha Bilder', ... );
Because "Content-Type:" is the only line used by b2evo, you may also just add
'' => 'Content-Type: text/plain; charset=ISO-8859-1', into your
- The locales that your plugin supports also need to be supported by b2evo. And the charset of the
_global.phpfile must be the same as defined there (see
- The Plugin has to use the
$this->T_('Hello world!');(and not the global function with the same name).
Submit plugin translations
If you want to translate some plugin, you basically have to get the existing
messages.po file (if there’s any) and update that, or get the template (
messages.pot), create a new translation based on it.
Then, submit the
messages.po file to the plugin author.