コード例 #1
0
 /**
  * Get i18n messages
  * @param bool $forceRefresh
  * @return
  */
 public function getMessagesInst($forceRefresh = false)
 {
     $crtLang = self::getLanguage();
     $messageCacheDir = dirname(AJXP_PLUGINS_MESSAGES_FILE) . "/i18n";
     $messageFile = $messageCacheDir . "/" . $crtLang . "_" . basename(AJXP_PLUGINS_MESSAGES_FILE);
     if (isset($this->configs["MESSAGES"]) && !$forceRefresh) {
         return $this->configs["MESSAGES"];
     }
     if (!isset($this->configs["MESSAGES"]) && is_file($messageFile)) {
         include $messageFile;
         if (isset($MESSAGES)) {
             $this->configs["MESSAGES"] = $MESSAGES;
         }
         if (isset($CONF_MESSAGES)) {
             $this->configs["CONF_MESSAGES"] = $CONF_MESSAGES;
         }
     } else {
         $this->configs["MESSAGES"] = array();
         $this->configs["CONF_MESSAGES"] = array();
         $nodes = AJXP_PluginsService::getInstance()->searchAllManifests("//i18n", "nodes");
         foreach ($nodes as $node) {
             $nameSpace = $node->getAttribute("namespace");
             $path = AJXP_INSTALL_PATH . "/" . $node->getAttribute("path");
             $lang = $crtLang;
             if (!is_file($path . "/" . $crtLang . ".php")) {
                 $lang = "en";
                 // Default language, minimum required.
             }
             if (is_file($path . "/" . $lang . ".php")) {
                 require $path . "/" . $lang . ".php";
                 if (isset($mess)) {
                     foreach ($mess as $key => $message) {
                         $this->configs["MESSAGES"][(empty($nameSpace) ? "" : $nameSpace . ".") . $key] = $message;
                     }
                 }
             }
             $lang = $crtLang;
             if (!is_file($path . "/conf/" . $crtLang . ".php")) {
                 $lang = "en";
             }
             if (is_file($path . "/conf/" . $lang . ".php")) {
                 require $path . "/conf/" . $lang . ".php";
                 $this->configs["CONF_MESSAGES"] = array_merge($this->configs["CONF_MESSAGES"], $mess);
             }
         }
         if (!is_dir($messageCacheDir)) {
             mkdir($messageCacheDir);
         }
         AJXP_VarsFilter::filterI18nStrings($this->configs["MESSAGES"]);
         AJXP_VarsFilter::filterI18nStrings($this->configs["CONF_MESSAGES"]);
         @file_put_contents($messageFile, "<?php \$MESSAGES = " . var_export($this->configs["MESSAGES"], true) . " ; \$CONF_MESSAGES = " . var_export($this->configs["CONF_MESSAGES"], true) . " ; ");
     }
     return $this->configs["MESSAGES"];
 }