From b2evolution manual
So you want to localize (mainly translate) b2evolution to your own language? Here's how to do it with minimum effort by using the gettext system provided by b2evo.
If this is the first time you are dealing with localization and/or gettext, you may want to read this background information first:
How to localize b2evo to your own language
- Check the already available locales in the [Language packs] area. (A locale is identified by a language code followed by a country code. For example en_US and en_GB are different, though similar, locales). If your locale already exists, check to see how complete it is. You may wish to contact the author of an existing translation and offer your help in updating / extending / finishing the translation.
- Translations should always be made against a specific release. You can download the latest stable release.
- Go to the directory /blogs/locales and create a new folder for the new locale by using the same pattern as the existing folder. The first two letters must be your ISO 639 language code. The last two letters must be your ISO 3166 country code. If there is already a locale similar to yours (same language), you may also copy its folder and rename it. That way, you'll benefit from the existing translations
- Inside of your locale folder, create a subfolder named LC_MESSAGES. Yes, this is a little funky, but it's a gettext convention. Your translations will be located in this subfolder. Namely, they'll be in a file called messages.po.
- If you're creating a brand new translation, you have no messages.po file yet. In that case, copy the file messages.pot from /locales to your LC_MESSAGES folder and rename it to messages.po .
- You could edit the messages.po file by hand but it's much easier with a dedicated tool such as poedit. 
- poedit runs on Windows as well as Linux and other Unix OSes. You can see from the screenshot how untranslated strings appear in blue, "fuzzy" translations (the ones you're unsure of and the ones automatically genereated when new strings are added to b2evo) appear in yellow, and translated strings appear in white.
- poedit will also let you add comments or read those the developer may have provided in the "".POT"" file.
- And best of all: poedit will show you all references of a given string in the source code. Even better, it will open the sources and highlight the occurrences for you. This way, you can really make sure what a string is used for when you're not sure about how to translate it! How cool is that?
- You now need to activate the locale in b2evolution. Open the file /conf/_locales.php and make the following changes:
- add an entry to the $locales array by duplicating an existing entry. Customize the locale, the charset you have used for translation and finally enter the default date and time formats for your country.
- you'll probably want to make the newly added locale your default locale (used in the backoffice and for notification messages). Do this by setting $default_locale. You will also have to update the locale for your user profile.
- decide if you want b2evolution to localize with the help of the gettext runtime functions ($use_l10n = 1) or with its own l10n system ($use_l10n = 2). The latter is generally better. (Note: there are situations where using the gettext runtime would fail miserably...). We strongly recommend you use the default setting (2).
- at the end of the file set $allow_po_extraction = 1;
- At this time, you should see your localization appear in the regional settings screen. Since you have set $allow_po_extraction = 1, you will see a link named [extract] for each locale. Click to extract the strings for your own locale. (This will create a file named _globals.php in your locale folder.)
- Your translations should now be active
- The blogs on the public pages, however, will be displayed in the language that has been set for them in the blogs configuration forms.
- Please note: if you make changes to your .po/.mo files after having used them in b2evolution, you may need to restart your webserver in order to clear gettext's internal cache and see your changes.
- Please contribute your translation to the [language packs] by following the instructions on that page.
You'll see, once you've installed the tools, localizing b2evolution is really easier than it seems!
More on updating already existing language files...
There is a second .POT file for the static html help pages that are displayed before the installation. This file is located in CVS:/b2evolution/gettext/langfiles/static.POT . If you have trouble obtaining this file, please ask us. We do not elaborate here because we will be reorganizing the POT files soon.
Formal vs Casual
In most languages a question arises as how to translate English: should the translation be in a formal or a casual style?
Well, b2evo is moving towards a profesionnal content management system more and more, so the answer would definitely be rather formal. (If you'd prefer a blog toy instead, there's plenty of them available on the Internet, though ;D)
One thing you could do is check out how applications like Microsoft Word are localized. You should use similar style.
Anyway, when in doubt, please use the formal style.
Works with b2evo 1.9 or later
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 ...
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 Version: Get xg.php. You will also need the file _pofile.class.php in the current directory, which you can get also from the CVS repository.
The process to create this is:
1. 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
2a. Then you'll need a messages.po file for every language (e.g. for de_DE). You'll have to do the following only to init the messages.po file 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
2b. If there's already a messages.po file for a locale, you can update it from messages.pot. The following will update
php -f xg.php CWD merge de_DE
3. Edit the messages.po file with a normal text editor or tool like poedit or KBabel. You should normally only have to update untranslated or fuzzy strings.
4. Convert the messages.po file to the final _global.php file. The following command will create a new <code>de_DE/_global.php file:
php -f xg.php CWD convert de_DE
5. Send your updated messages.po and _global.php files to the Plugin maintainer (if you are not maintaining it yourself, of course)
Plugins only use the _global.php file, not the messages.pot or 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 _global.php file(s).
- 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 Plugin::T_() method, e.g.
$this->T_('Hello world!');(and not the global function with the same name).