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:
When you translate, you don’t translate to your language. You translate to your Locale. 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.
Transifex is the collaborative translation platform we use. It allows several people to translate to the same locale. They can even translate at the same time, if necessary.
In order to get started translating b2evolution to your own locale, all you need to do is this:
- Go to Transifex and create an account if you don’t have one already. It is 100% Free for translators (and also for Open Source projects in general).
- On the b2evolution project page, select you language / locale. If it doesn’t exist yet, click on "+ Create Language". (Note: If you are going to create a locale similar to another (for example pt_BR vs pt_PT), you can also open an existing locale and click on "Clone to new language".)
- On your language page, select a resource. You can always start with
messages.po
which is the main and most important resource to translate. - Click on "Translate now" and off you go. Every string you translate and save will be contributed to the project!
Note: if you already have a local version of the messages.po
file (from an old language pack or previous work), instead of "Translate now", you can click on ‘Upload file". Note: your file must be encoded in UTF-8 before you can upload it to Transifex. (You can change the encoding in PO Edit, if needed.)
You don’t really need to go deeper into this page until, say, your language/locale has at least 10% to 15% translated.
Important: only use Transifex for translating the latest public release. Do not use it for translating old versions of b2evolution. The text strings may differ.
If you are an experimented software translator, you could export and download the messages.po
from Transifex, edit it locally on your computer, and then reupload it to Transifex. If you do this, you can use a tool like messages.po
for easy editing of the .PO file.
This method is more complicated than editing directly on Transifex. However it allows a more direct access to the source code during translation, which may be useful in some cases. PO Edit 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!
Once your translation is complete, you need to package it into a language pack so that b2evolution can use it.
- Check if your locale is already available for download in the Language packs area or if it has been posted to the forums by someone. It may be a good starting point.
- Go to the directory
/locales
and duplicate the folder of an existing locale like fr_FR
(or unzip your old/existing language pack there). Name the new folder to reflect the locale of your new language pack, for example de_DE
for a Swiss German language pack.
- The first two letters must be your ISO 639 language code.
- The next two letters must be your ISO 3166 country code.
- You may add a 3rd part the the folder name to specify the charset of your locale, but all new locales should use UTF-8 now, so you should typically skip this, even if you see older locales with a specific charset.
your locale folder, you should find a subfolder named LC_MESSAGES
. Yes, this is a little funky, but it’s a gettext convention. In Transifex, click on "Download for use" to download the latest messages.po
file. Note that this file will always be encoded in UTF-8. Put this file in the LC_MESSAGES
folder. Rename an existing locale definition file like fr-FR.locale
to reflect your new locale, for example de-CH.locale
for Swiss German. Inside that file, change the name of the locale as well as the date format and other variables, if need be. Make sure the charset is set to 'utf-8'
. Here is an example:<?php
$locale_defs['fr-FR'] = array(
'name' => NT_('French (FR) utf-8'),
'messages' => 'fr_FR',
'charset' => 'utf-8',
'datefmt' => 'd.m.y',
'timefmt' => 'H:i:s',
'startofweek' => 1,
'transliteration_map' => array(),
);
?>
The .po
format is not very efficient. So we need to compile it the .php
. We’ll use b2evolution’s embedded tool for doing that.
- Open the file
/conf/_locales.php
and change the value of $allow_po_extraction = 0;
to
$allow_po_extraction = 1;
- At this time, if you go to the regional settings screen and click "Restore Default Locales", you will see your locale appear.
- Since you have set
$allow_po_extraction = 1
, you can, click "Show translation info’. - You will now see a link named [extract] for each locale. Click to extract the strings for your own locale. (This will create or update a file named
_globals.php
in your locale folder.) - Your translations should now be active
At this point, your locale is active. However, note that blogs on the public pages will be displayed in the language that has been set for them in the blogs configuration forms. So you may need to change the locale setting of each blog you want to appear translated.
Please contribute your translation to the language packs by following the instructions on that page.
There is a second resource in Transifex called static.po
. It contains the strings of the html help pages that are displayed in the b2evolution package before the installation.
For this file you are also kindly invited to provide translations on Transifex.
There are no language packs to compile for this file. These are the welcome messages of the b2evolution package. The translations will go directly into the b2evolution release packages.
Is there an option so you can choose ON your website which language you want? So the visitors can choose