コード例 #1
0
 /**
  * Set locale
  * It will require the correct file and init the needed vars
  *
  * @param string $language The language to load.
  */
 public static function setLocale($language)
 {
     $language = (string) $language;
     // require the BackendLocaleModel
     require_once BACKEND_MODULES_PATH . '/locale/engine/model.php';
     // validate file, generate it if needed
     if (!SpoonFile::exists(BACKEND_CACHE_PATH . '/locale/en.php')) {
         BackendLocaleModel::buildCache('en', APPLICATION);
     }
     if (!SpoonFile::exists(BACKEND_CACHE_PATH . '/locale/' . $language . '.php')) {
         BackendLocaleModel::buildCache($language, APPLICATION);
     }
     // store
     self::$currentInterfaceLanguage = $language;
     // attempt to set a cookie
     try {
         // store in cookie
         CommonCookie::set('interface_language', $language);
     } catch (SpoonCookieException $e) {
         // settings cookies isn't allowed, because this isn't a real problem we ignore the exception
     }
     // init vars
     $err = array();
     $lbl = array();
     $msg = array();
     // set English translations, they'll be the fallback
     require BACKEND_CACHE_PATH . '/locale/en.php';
     self::$err = (array) $err;
     self::$lbl = (array) $lbl;
     self::$msg = (array) $msg;
     // overwrite with the requested language's translations
     require BACKEND_CACHE_PATH . '/locale/' . $language . '.php';
     foreach ($err as $module => $translations) {
         if (!isset(self::$err[$module])) {
             self::$err[$module] = array();
         }
         self::$err[$module] = array_merge(self::$err[$module], $translations);
     }
     foreach ($lbl as $module => $translations) {
         if (!isset(self::$lbl[$module])) {
             self::$lbl[$module] = array();
         }
         self::$lbl[$module] = array_merge(self::$lbl[$module], $translations);
     }
     foreach ($msg as $module => $translations) {
         if (!isset(self::$msg[$module])) {
             self::$msg[$module] = array();
         }
         self::$msg[$module] = array_merge(self::$msg[$module], $translations);
     }
 }
コード例 #2
0
ファイル: language.php プロジェクト: netconstructor/forkcms
 /**
  * Set locale
  * It will require the correct file and init the needed vars
  *
  * @return	void
  * @param	string $language		The language to load.
  */
 public static function setLocale($language)
 {
     // redefine
     $language = (string) $language;
     // check if file exists
     if (!SpoonFile::exists(BACKEND_CACHE_PATH . '/locale/' . $language . '.php')) {
         // require the BackendLocaleModel
         require_once BACKEND_MODULES_PATH . '/locale/engine/model.php';
         // build locale file
         BackendLocaleModel::buildCache($language, APPLICATION);
     }
     // store
     self::$currentInterfaceLanguage = $language;
     // attempt to set a cookie
     try {
         // store in cookie
         SpoonCookie::set('interface_language', $language);
     } catch (SpoonCookieException $e) {
         // settings cookies isn't allowed, because this isn't a real problem we ignore the exception
     }
     // store in session for TinyMCE
     SpoonSession::set('tiny_mce_language', $language);
     SpoonSession::set('interface_language', $language);
     // init vars
     $err = array();
     $lbl = array();
     $msg = array();
     // require file
     require BACKEND_CACHE_PATH . '/locale/' . $language . '.php';
     // set language specific labels
     self::$err = (array) $err;
     self::$lbl = (array) $lbl;
     self::$msg = (array) $msg;
 }