To deal with different l10ns and i18n strings Limb makes use of 'locale' and 'strings' classes('LIMB_DIR/core/lib/locale/' directory).
Limb uses two constants to deal with localization settings:
Each Limb site object has its locale id (e.g 'en' or 'ru'). It is stored in the sys_site_object table. Every new object inherits from its parent locale id by default. At the moment we don't have a nice GUI for setting site object's locale id(this is planned).
It's the /core/filters/locale_definition_filter.class.php which is responsible for defining CONTENT_LOCALE_ID and MANAGEMENT_LOCALE_ID. It uses pretty much guessing and it will be simpler to show its code than trying to explain:
[...] if(!$node = map_request_to_node($request)) { if(!defined('CONTENT_LOCALE_ID')) define('CONTENT_LOCALE_ID', DEFAULT_CONTENT_LOCALE_ID); if(!defined('MANAGEMENT_LOCALE_ID')) define('MANAGEMENT_LOCALE_ID', CONTENT_LOCALE_ID); $locale =& locale :: instance(); $locale->setlocale(); $filter_chain->next(); return; } if(!defined('CONTENT_LOCALE_ID')) { if($object_locale_id = site_object :: get_locale_by_id($node['object_id'])) define('CONTENT_LOCALE_ID', $object_locale_id); else define('CONTENT_LOCALE_ID', DEFAULT_CONTENT_LOCALE_ID); } if(!defined('MANAGEMENT_LOCALE_ID')) { $user = user :: instance(); if($user_locale_id = $user->get_locale_id()) define('MANAGEMENT_LOCALE_ID', $user_locale_id); else define('MANAGEMENT_LOCALE_ID', CONTENT_LOCALE_ID); } [...]
User can set preferred MANAGEMENT_LOCALE_ID during logging into a site:
It is also possible to switch MANAGEMENT_LOCALE_ID using the upper-right form in the administrative part of the site:
The list of available locales is defined by global constant AVAILABLE_LOCALES in setup.php(or setup.override.php) in the PROJECT_DIR. The valid example is:
@define('AVAILABLE_LOCALES', 'en,ru');
Let's see how and where these locale constants are used:
You can find and l10n settings files in the 'LIMB_DIR/core/locale/' directory. There are 2 currently supported: en.ini, ru.ini. These files contain some l10n specific stuff: country name, language name, date format, week days, month names, page charset etc
For now we have localized strings for English and Russian languages. The common usage of the strings class is:
echo strings :: get($string_name,[$file_name='common'],[$locale_id=null]);
if $locale_id is not specified current MANAGEMENT_LOCALE_ID is used $file_name is mapped to physical file by schema(order is preserved):
If no file found the critical error is risen.
The common format of the localized ini file as follows:
[constants] attribute1 = ... attribute2 = ... ...
Localized ini files support simple inheritance with [extends] section: you have to supply 'filename' property in it to let strings class handle inheritance issues. Simple example, contents of ad_en.ini file:
[constants] create_ad_block = Create ad block ad_block_creation = Ad block creation ad_block_edition = Ad block edition edit_ad_block = Edit ad block
Обсуждение