public function set($LocaleName)
{
$CurrentLocale = self::canonicalize($LocaleName);
// Get locale sources
$this->Locale = $CurrentLocale;
if ($this->addonManager !== null) {
$LocaleSources = $this->addonManager->getEnabledTranslationPaths($CurrentLocale);
} else {
$LocaleSources = [];
}
$Codeset = c('Garden.LocaleCodeset', 'UTF8');
$SetLocale = array(LC_TIME, "{$CurrentLocale}.{$Codeset}", $CurrentLocale);
list($Language) = explode('_', $CurrentLocale, 2);
if (isset(self::$SetLocales[$Language])) {
$FullLocales = (array) self::$SetLocales[$Language];
foreach ($FullLocales as $FullLocale) {
$SetLocale[] = "{$FullLocale}.{$Codeset}";
$SetLocale[] = $FullLocale;
}
}
$r = call_user_func_array('setlocale', $SetLocale);
if (!is_array($LocaleSources)) {
$LocaleSources = array();
}
// Create a locale config container
$this->unload();
$ConfLocaleOverride = PATH_CONF . '/locale.php';
foreach ($LocaleSources as $localeSource) {
if ($ConfLocaleOverride != $localeSource && file_exists($localeSource)) {
// Don't double include the conf override file... and make sure it comes last
$this->load($localeSource, false);
}
}
// Also load any custom defined definitions from the conf directory
if (file_exists($ConfLocaleOverride)) {
$this->load($ConfLocaleOverride, true);
}
// Prepare developer mode if needed
$this->DeveloperMode = c('Garden.Locales.DeveloperMode', false);
if ($this->DeveloperMode) {
$this->DeveloperContainer = new Gdn_Configuration();
$this->DeveloperContainer->splitting(false);
$this->DeveloperContainer->caching(false);
$DeveloperCodeFile = PATH_CACHE . "/locale-developer-{$LocaleName}.php";
if (!file_exists($DeveloperCodeFile)) {
touch($DeveloperCodeFile);
}
$this->DeveloperContainer->load($DeveloperCodeFile, 'Definition', true);
}
// Import core (static) translations
if ($this->DeveloperMode) {
$this->DeveloperContainer->massImport($this->LocaleContainer->get('.'));
}
// Allow hooking custom definitions
$this->fireEvent('AfterSet');
}