Ejemplo n.º 1
0
 public function __construct($language, $langstr = null)
 {
     if ($langstr == null) {
         $langstr = array();
     }
     $this->_name = $language;
     $systemLocale = $this->getIsoName();
     $options = array($systemLocale . ".UTF8", $systemLocale . ".UTF-8", $systemLocale . ".utf8", $systemLocale . ".utf-8", $systemLocale, $language, $this->_name);
     $this->_cultureActive = setlocale(LC_ALL, $options);
     // Try to load in Windows if failed before
     if (!$this->_cultureActive) {
         $row = LocaleFactory::getInfoLocaleDB('shortname', $this->getName());
         $langstr = $row->getFieldArray("langstr");
         $iLang = 0;
         while (!$this->_cultureActive && $iLang < count($langstr)) {
             $this->_cultureActive = setlocale(LC_ALL, $langstr[$iLang]);
             $iLang++;
         }
     }
     if (!$this->_cultureActive) {
         $firstPart = substr($language, 0, 2);
         if (FileUtil::isWindowsOS()) {
             $complement = "";
         } else {
             $complement = "Only the languages available in 'locale -a' can be setted. On debian try execute 'apt-get install language-pack-{$firstPart}'.";
         }
         echo "<br/>\n<b>Warning: </b> The culture language '{$language}' was not found. {$complement}\n<br/>";
         // I cant call the context here because it's call CultureInfo but the context is not complete yet.
         //$context = Context::getInstance();
         //$context->WriteWarningMessage ("");
     }
     $this->_localeConv = localeConv();
     #if (stripos(PHP_OS, 'win') !== false)
     #{
     #	$this->_localeConv["currency_symbol"] = utf8_encode($this->_localeConv["currency_symbol"]);
     #}
     #Debug::PrintValue($this->_localeConv, $langstr, $this->getRegionalMonthNames());
 }
Ejemplo n.º 2
0
 /**
  *
  * @param type $str
  */
 public function setLocale($str = "")
 {
     $lang = strtolower($str == "" ? $this->getParameter("lang") : $str);
     $langAvail = array_keys($this->LanguagesAvailable());
     // Get the languages to check
     if (!empty($str)) {
         $checkLang = array($str);
     } else {
         if (!empty($lang)) {
             $checkLang = array($lang);
         } else {
             $checkLang = $langAvail;
         }
     }
     // Language Negotiator
     $langNeg = new LanguageNegotiator();
     $langAccepted = $langNeg->getBest(isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : "en-us", $checkLang);
     if (is_null($langAccepted)) {
         $currentLanguage = !empty($str) ? $str : (!empty($lang) ? $lang : $langAvail[0]);
     } else {
         $currentLanguage = strtolower($langAccepted->getValue());
     }
     // Get the correct language
     $selected = array_merge(preg_grep("/^" . $currentLanguage . "*/", $langAvail), preg_grep("/^" . substr($currentLanguage, 0, 2) . "*/", $langAvail));
     if (count($selected) == 0) {
         $currentLanguage = $langAvail[0];
     } else {
         $currentLanguage = array_shift($selected);
     }
     $this->_lang = LocaleFactory::GetLocale($currentLanguage);
     $this->addPairToConfig("LANGUAGE", $this->_lang->getName());
     $this->addPairToConfig("LANGUAGENAME", $this->_lang->getLanguage());
 }