Exemple #1
0
 /**
  * Include the good language dict.
  *
  * Get the default language from current user in $_SESSION["glpilanguage"].
  * And load the dict that correspond.
  *
  * @param $forcelang Force to load a specific lang (default '')
  *
  * @return nothing (make an include)
  **/
 static function loadLanguage($forcelang = '')
 {
     global $LANG, $CFG_GLPI, $TRANSLATE;
     $file = "";
     if (!isset($_SESSION["glpilanguage"])) {
         if (isset($CFG_GLPI["language"])) {
             // Default config in GLPI >= 0.72
             $_SESSION["glpilanguage"] = $CFG_GLPI["language"];
         } else {
             if (isset($CFG_GLPI["default_language"])) {
                 // Default config in GLPI < 0.72 : keep it for upgrade process
                 $_SESSION["glpilanguage"] = $CFG_GLPI["default_language"];
             } else {
                 $_SESSION["glpilanguage"] = "en_GB";
             }
         }
     }
     $trytoload = $_SESSION["glpilanguage"];
     // Force to load a specific lang
     if (!empty($forcelang)) {
         $trytoload = $forcelang;
     }
     // If not set try default lang file
     if (empty($trytoload)) {
         $trytoload = $CFG_GLPI["language"];
     }
     if (isset($CFG_GLPI["languages"][$trytoload])) {
         $newfile = "/locales/" . $CFG_GLPI["languages"][$trytoload][1];
     }
     if (empty($newfile) || !is_file(GLPI_ROOT . $newfile)) {
         $newfile = "/locales/en_GB.mo";
     }
     if (isset($CFG_GLPI["languages"][$trytoload][5])) {
         $_SESSION['glpipluralnumber'] = $CFG_GLPI["languages"][$trytoload][5];
     }
     $TRANSLATE = new Zend\I18n\Translator\Translator();
     try {
         $cache = Zend\Cache\StorageFactory::factory(array('adapter' => 'apc'));
         $TRANSLATE->setCache($cache);
     } catch (Zend\Cache\Exception\ExtensionNotLoadedException $e) {
         // ignore when APC not available
         // toolbox::logDebug($e->getMessage());
     }
     $TRANSLATE->addTranslationFile('gettext', GLPI_ROOT . $newfile, 'glpi', $trytoload);
     // Load plugin dicts
     if (isset($_SESSION['glpi_plugins']) && is_array($_SESSION['glpi_plugins'])) {
         if (count($_SESSION['glpi_plugins'])) {
             foreach ($_SESSION['glpi_plugins'] as $plug) {
                 Plugin::loadLang($plug, $forcelang, $trytoload);
             }
         }
     }
     // TRANSLATION_MODE deleted : maybe find another solution ?
     // Debug display lang element with item
     //       if ($_SESSION['glpi_use_mode'] == Session::TRANSLATION_MODE && $CFG_GLPI["debug_lang"]) {
     //          foreach ($LANG as $module => $tab) {
     //             foreach ($tab as $num => $val) {
     //                $LANG[$module][$num] = "".$LANG[$module][$num].
     //                                       "/<span style='font-size:12px; color:red;'>$module/$num</span>";
     //             }
     //          }
     //       }
     $TRANSLATE->setLocale($trytoload);
     return $trytoload;
 }
Exemple #2
0
 /**
  * Include the good language dict.
  *
  * Get the default language from current user in $_SESSION["glpilanguage"].
  * And load the dict that correspond.
  *
  * @param $forcelang Force to load a specific lang (default '')
  *
  * @return nothing (make an include)
  **/
 static function loadLanguage($forcelang = '')
 {
     global $LANG, $CFG_GLPI, $TRANSLATE;
     $file = "";
     if (!isset($_SESSION["glpilanguage"])) {
         if (isset($CFG_GLPI["language"])) {
             // Default config in GLPI >= 0.72
             $_SESSION["glpilanguage"] = $CFG_GLPI["language"];
         } else {
             if (isset($CFG_GLPI["default_language"])) {
                 // Default config in GLPI < 0.72 : keep it for upgrade process
                 $_SESSION["glpilanguage"] = $CFG_GLPI["default_language"];
             } else {
                 $_SESSION["glpilanguage"] = "en_GB";
             }
         }
     }
     $trytoload = $_SESSION["glpilanguage"];
     // Force to load a specific lang
     if (!empty($forcelang)) {
         $trytoload = $forcelang;
     }
     // If not set try default lang file
     if (empty($trytoload)) {
         $trytoload = $CFG_GLPI["language"];
     }
     if (isset($CFG_GLPI["languages"][$trytoload])) {
         $newfile = "/locales/" . $CFG_GLPI["languages"][$trytoload][1];
     }
     if (empty($newfile) || !is_file(GLPI_ROOT . $newfile)) {
         $newfile = "/locales/en_GB.mo";
     }
     $TRANSLATE = new Zend\I18n\Translator\Translator();
     try {
         $cache = Zend\Cache\StorageFactory::factory(array('adapter' => 'apc'));
         $TRANSLATE->setCache($cache);
     } catch (Zend\Cache\Exception\ExtensionNotLoadedException $e) {
         // ignore when APC not available
         // toolbox::logDebug($e->getMessage());
     }
     $TRANSLATE->addTranslationFile('gettext', GLPI_ROOT . $newfile, 'glpi', $trytoload);
     // Test APC version, if is enable with special check for cli
     //      if (version_compare(phpversion('apc'), '3.1.6') >= 0
     //          && ini_get('apc.enabled')
     //          && (!isCommandLine() || ini_get('apc.enable_cli'))) { // Try from APC cache
     ////          $key       = "glpi".sha1_file(GLPI_ROOT.$newfile); // Use content to detect changes
     //         $cache = Zend\Cache\StorageFactory::factory(array('adapter' => 'apc',
     //                                                           'plugins' => array('exception_handler'
     //                                                                               => array('throw_exceptions'
     //                                                                                         => false))));
     //         $TRANSLATE->setCache($cache);
     //         $TRANSLATE->addTranslationFile('gettext', GLPI_ROOT.$newfile, 'glpi', $trytoload);
     //
     //      } else if (function_exists('xcache_get') && !isCommandLine()) { // Try from XCache
     //         // TODO : use xcache adapter of Zend when available (2.1)
     //         // see http://framework.zend.com/issues/browse/ZF2-543
     //         $key = "glpi".sha1_file(GLPI_ROOT.$newfile); // Use content to detect changes
     //         if (@xcache_isset($key)) {
     //            $TRANSLATE = unserialize(xcache_get($key));
     //         }
     //         if (!$TRANSLATE) {
     //            $TRANSLATE = new Zend\I18n\Translator\Translator;
     //            $TRANSLATE->addTranslationFile('gettext', GLPI_ROOT.$newfile, 'glpi', $trytoload);
     //         }
     //         $tmp = xcache_set($key, serialize($TRANSLATE));
     //      } else {
     //         $TRANSLATE = new Zend\I18n\Translator\Translator;
     //         $TRANSLATE->addTranslationFile('gettext', GLPI_ROOT.$newfile, 'glpi', $trytoload);
     //      }
     // Load plugin dicts
     if (isset($_SESSION['glpi_plugins']) && is_array($_SESSION['glpi_plugins'])) {
         if (count($_SESSION['glpi_plugins'])) {
             foreach ($_SESSION['glpi_plugins'] as $plug) {
                 Plugin::loadLang($plug, $forcelang, $trytoload);
             }
         }
     }
     // TRANSLATION_MODE deleted : maybe find another solution ?
     // Debug display lang element with item
     //       if ($_SESSION['glpi_use_mode'] == Session::TRANSLATION_MODE && $CFG_GLPI["debug_lang"]) {
     //          foreach ($LANG as $module => $tab) {
     //             foreach ($tab as $num => $val) {
     //                $LANG[$module][$num] = "".$LANG[$module][$num].
     //                                       "/<span style='font-size:12px; color:red;'>$module/$num</span>";
     //             }
     //          }
     //       }
     $TRANSLATE->setLocale($trytoload);
     return $trytoload;
 }