public static function setLocale($language = null, $force = false)
{
// redefine
$language = $language !== null ? (string) $language : LANGUAGE;
// validate language
if (!$force && !in_array($language, self::getActiveLanguages())) {
throw new Exception('Invalid language (' . $language . ').');
}
// validate file, generate it if needed
$filesystem = new Filesystem();
if (!$filesystem->exists(FRONTEND_CACHE_PATH . '/Locale/en.json')) {
self::buildCache('en', 'Frontend');
}
if (!$filesystem->exists(FRONTEND_CACHE_PATH . '/Locale/' . $language . '.json')) {
self::buildCache($language, 'Frontend');
}
// set English translations, they'll be the fallback
$fallbackTranslations = json_decode(file_get_contents(FRONTEND_CACHE_PATH . '/Locale/en.json'), true);
self::$fallbackAct = (array) $fallbackTranslations['act'];
self::$fallbackErr = (array) $fallbackTranslations['err'];
self::$fallbackLbl = (array) $fallbackTranslations['lbl'];
self::$fallbackMsg = (array) $fallbackTranslations['msg'];
// We will overwrite with the requested language's translations upon request
$translations = json_decode(file_get_contents(FRONTEND_CACHE_PATH . '/Locale/' . $language . '.json'), true);
self::$act = (array) $translations['act'];
self::$err = (array) $translations['err'];
self::$lbl = (array) $translations['lbl'];
self::$msg = (array) $translations['msg'];
}