Gettext
From MapbenderWiki
Contents |
API
https://svn.osgeo.org/mapbender/trunk/mapbender/documents/api_js/files/plugins/mb_i18n-js.html
gettext
Static data in PHP files may be translated via gettext. All strings that will be translated must be called with the PHP gettext method, example
echo _("Not an integer value"); //_() is short for gettext()
- more gettext examples and conventions
BEWARE: Mapbender uses a function _mb() to wrap _() (scenario: you might want to disable i18n even though gettext is installed)
echo _mb("Not an integer value"); //_mb() is a wrapper for _()
Installation
php extension gettext
- activate the gettext extension for php
Utility programms
- UNIX
apt-get install gettext
- Windows
- Installation of Poedit (http://www.poedit.net/download.php#win32)
- in the bin directory you will find msgfmt.exe and xgettext.exe
.po file
The .po file is a text file containing keys and values. The keys are the input values to the _() function, like "Not an integer value"
The .po file segemnt will look like this
msgid "Not an integer value." msgstr "Kein Integer-Wert."
.po files are stored in /resources/locale/<locale_name>/LC_MESSAGES/, example
/resources/locale/de_DE/LC_MESSAGES/
to create a .po file for a new language (for example german), use xgettext
xgettext -p <folder>/resources/locale/de_DE/LC_MESSAGES/ -o Mapbender.po -L php -j --keyword=_mb -n --from-code utf-8 <folder>/http/php/*.php -p locale path, target directory -o output-file -L language -j merge with existing po file -n add metadata --from-code encoding of php file --keyword name of the function in the source code
- translations can be done via POEdit
.mo file
The .mo file is a binary representation of the text file. It is required to compile the .mo file from the .po file on the system where Mapbender is installed. There is no sense in shipping it with Mapbender. The .po file is automatically compiled into an .mo file if you save the .po file in POEdit.
Compile the .mo file via command line like this
msgfmt resources/locale/de_DE/LC_MESSAGES/Mapbender.po -o resources/locale/de_DE/LC_MESSAGES/Mapbender.mo
msgfmt is part of the gettext package, install it via
apt-get install gettext
if necessary.
- for an example, see module print_PDF.php
gted (Gettext editor) is a nice Eclipse Plug-In for translating PO files.
System-locale
To start a gui in german language (for example) try to find out what locales are supported on your system via
locale -a
You need to find out the name for german, it should be one of the following:
de_DE.utf8 German_Germany.1252 de_DE
If your german locale has a different name, we need to add it to class_locale.php
If no german locale is configured on your server, add one with:
sudo dpkg-reconfigure locales
If you want to have a gui in other languages (portuguese, french, spanish, italian, bulgarian, hungarian, these are supported right now), you have to install these locales on your server:
bg_BG.utf8 es_ES.utf8 fr_FR.utf8 it_IT.utf8 hu_HU.utf8 pt_PT.utf8
