Locale
From MapbenderWiki
A locale allows region and language specific behaviour
Contents |
Definition
The locale is a string representing a language and additionally, a location and a character set. This syntax usually is <language>_<location>.<charset>
Mapbender uses the actual system locale name internally, for example
de_DE.utf8
on Linux or
1252
on Windows machines.
File system
In the file system we need a folder for each locale
resources/locale/<locale>/LC_MESSAGES
for example
resources/locale/de_DE/LC_MESSAGES
This folder will hold the gettext translation files, Mapbender.po and Mapbender.mo
PHP class Mb_locale
See Mb_locale
Sets the locale, depending on various settings:
- a language ID passed to the constructor
- a default language (see mapbender.conf)
- the browser settings $_SERVER["HTTP_ACCEPT_LANGUAGE"]
usage:
$localeObj = new Mb_locale("de");
the locale is stored in
$localeObj->name
The locale needs to be set in every PHP file that uses l10n. At the moment located in core/globalSettings.php, which should be required in any script.
The current locale is saved in the session as
$_SESSION["mb_locale"]
The language ID is also stored in the session as
$_SESSION["mb_lang"]
gettext
After the locale has been set in class Mb_locale via
setlocale(LC_ALL, $_SESSION["mb_locale"]);
we need to bind the folder to a domain. The domain name must be equal to the name of the .po and .mo file name.
bindtextdomain("Mapbender", dirname(__FILE__)."/../resources/locale/");
After this, we set the current text domain
textdomain("Mapbender");
Now gettext will look up translations in the Mapbender.mo file in the specified directory.
