MySource Matrix Developer

Main Content

Locale Manager

The Locale Manager is the core part of MySource Matrix's localisation capability. It is responsible for keeping track of the current locale, loading localised resources where appropriate, and making available localised resources to other parts of MySource Matrix.

The Locale Manager is always available within the main MySource object, much like the Asset Manager. It is accessible in code outside of the MySource and Locale Manager objects using the following:

<?php
$GLOBALS['SQ_SYSTEM']->lm
?>

Current Locale

The Locale Manager has a concept of a current locale, based on the default Backend Locale settings on the System Configuration screen, and the user that is currently logged in.

The history of the current locale are stored in a stack, and is set using the setCurrentLocale() and restoreCurrentLocale() methods. Typically, these will be first set during initialisation of the MySource Matrix system, and then set and restored as the MySource class' current user stack is similarly set and restored. The current locale code itself is accessible using the getCurrentLocale() method.

The extended name of the current locale (as seen on the System Configuration screen) is returned using the getLocaleName() method. This accepts one parameter - the locale code, which defaults to the current locale if not specified.

Note: The list of locale names is stored in the file [SYSTEM ROOT]/fudge/standards_lists/locales.inc.

<?php
$locale_code = $GLOBALS['SQ_SYSTEM']->lm->getCurrentLocale();
$locale_name = $GLOBALS['SQ_SYSTEM']->lm->getLocaleName();
$GLOBALS['SQ_SYSTEM']->lm->setCurrentLocale(string $locale_name);
$GLOBALS['SQ_SYSTEM']->lm->restoreCurrentLocale();
?>

Shorthand Functions

Shorthand functions for some of the Locale Manager's most used functionality are available in the [SYSTEM ROOT]/core/include/general.inc file.

<?php
translate('string_code');
trigger_localised_error('CORE0000', E_USER_WARNING);
?>

Including Resources

<?php
$GLOBALS['SQ_SYSTEM']->lm->includeCoreStrings(string $locale);
$GLOBALS['SQ_SYSTEM']->lm->includePackageStrings(string $package_name[, string $locale]);
$GLOBALS['SQ_SYSTEM']->lm->includeAssetStrings(string $type_code[, string $locale]);
?>

Retrieving Resources

<?php
$GLOBALS['SQ_SYSTEM']->lm->getString(string $string_code);
$GLOBALS['SQ_SYSTEM']->lm->getErrorMessage(string $code);
$GLOBALS['SQ_SYSTEM']->lm->getInternalMessageSubject(string $type, array $keywords[, string $locale]);
$GLOBALS['SQ_SYSTEM']->lm->getInternalMessageBody(string $type, array $keywords[, string $locale]);
?>