/** * Set locale * * @param string[optional] $language The language to load, if not provided we will load the language based on the URL. * @param bool[optional] $force Force the language, so don't check if the language is active. */ public static function setLocale($language = null, $force = false) { // redefine $language = $language !== null ? (string) $language : FRONTEND_LANGUAGE; // validate language if (!$force && !in_array($language, self::getActiveLanguages())) { throw new FrontendException('Invalid language (' . $language . ').'); } // validate file, generate it if needed if (!SpoonFile::exists(FRONTEND_CACHE_PATH . '/locale/en.php')) { self::buildCache('en', 'frontend'); } if (!SpoonFile::exists(FRONTEND_CACHE_PATH . '/locale/' . $language . '.php')) { self::buildCache($language, 'frontend'); } // init vars $act = array(); $err = array(); $lbl = array(); $msg = array(); // set English translations, they'll be the fallback require FRONTEND_CACHE_PATH . '/locale/en.php'; self::$act = (array) $act; self::$err = (array) $err; self::$lbl = (array) $lbl; self::$msg = (array) $msg; // overwrite with the requested language's translations require FRONTEND_CACHE_PATH . '/locale/' . $language . '.php'; self::$act = array_merge(self::$act, (array) $act); self::$err = array_merge(self::$err, (array) $err); self::$lbl = array_merge(self::$lbl, (array) $lbl); self::$msg = array_merge(self::$msg, (array) $msg); }
/** * Set locale * * @return void * @param string[optional] $language The language to load, if not provided we will load the language based on the URL. * @param bool[optional] $force Force the language, so don't check if the language is active. */ public static function setLocale($language = null, $force = false) { // redefine $language = $language !== null ? (string) $language : FRONTEND_LANGUAGE; // validate language if (!$force && !in_array($language, self::getActiveLanguages())) { throw new FrontendException('Invalid language (' . $language . ').'); } // validate file, generate it if needed if (!SpoonFile::exists(FRONTEND_CACHE_PATH . '/locale/' . $language . '.php')) { self::buildCache($language, APPLICATION); } // init vars $act = array(); $err = array(); $lbl = array(); $msg = array(); // require file require FRONTEND_CACHE_PATH . '/locale/' . $language . '.php'; // set language specific labels self::$act = (array) $act; self::$err = (array) $err; self::$lbl = (array) $lbl; self::$msg = (array) $msg; }