public function beginRequest($sender, $param)
 {
     if (null == ($culture = $this->Request['lang'])) {
         if (null !== ($cookie = $this->Request->Cookies['lang'])) {
             $culture = $cookie->getValue();
         }
     }
     if (is_string($culture)) {
         $info = new CultureInfo();
         if ($info->validCulture($culture)) {
             $this->setCulture($culture);
             $this->Response->Cookies[] = new THttpCookie('lang', $culture);
         }
     }
 }
 function testCultureList()
 {
     $allCultures = CultureInfo::getCultures();
     $neutralCultures = CultureInfo::getCultures(CultureInfo::NEUTRAL);
     $specificCultures = CultureInfo::getCultures(CultureInfo::SPECIFIC);
     //there should be 246 cultures all together.
     $this->assertEqual(count($allCultures), 246);
     $this->assertEqual(count($neutralCultures), 76);
     $this->assertEqual(count($specificCultures), 170);
 }
예제 #3
0
 /**
  * Get a list of languages acceptable by the client browser
  * @return array languages ordered in the user browser preferences.
  */
 function getLanguages()
 {
     if ($this->languages !== null) {
         return $this->languages;
     }
     $this->languages = array();
     if (!isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
         return $this->languages;
     }
     //$basedir = CultureInfo::dataDir();
     //$ext = CultureInfo::fileExt();
     $info = new CultureInfo();
     foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $lang) {
         // Cut off any q-value that might come after a semi-colon
         if ($pos = strpos($lang, ';')) {
             $lang = trim(substr($lang, 0, $pos));
         }
         if (strstr($lang, '-')) {
             $codes = explode('-', $lang);
             if ($codes[0] == 'i') {
                 // Language not listed in ISO 639 that are not variants
                 // of any listed language, which can be registerd with the
                 // i-prefix, such as i-cherokee
                 if (count($codes) > 1) {
                     $lang = $codes[1];
                 }
             } else {
                 for ($i = 0, $k = count($codes); $i < $k; ++$i) {
                     if ($i == 0) {
                         $lang = strtolower($codes[0]);
                     } else {
                         $lang .= '_' . strtoupper($codes[$i]);
                     }
                 }
             }
         }
         if ($info->validCulture($lang)) {
             $this->languages[] = $lang;
         }
     }
     return $this->languages;
 }
 public function beginRequest($sender, $param)
 {
     $culture = $this->Request['lang'];
     if (null == $culture) {
         if (null !== ($cookie = $this->Request->Cookies['lang'])) {
             $culture = $cookie->getValue();
         }
     }
     if (is_string($culture)) {
         $info = new CultureInfo();
         if ($info->validCulture($culture)) {
             if (!in_array($culture, explode(";", $this->AvailableCultures))) {
                 $culture = "en";
             }
         } else {
             $culture = "en";
         }
     } else {
         $culture = "en";
     }
     $this->setCulture($culture);
     $this->Response->Cookies[] = new THttpCookie('lang', $culture);
 }
 /**
  * Set the Culture by using the GET URL.
  */
 function init()
 {
     //initialize other information.
     parent::init();
     $cookiename = 'I18N_Example_lang';
     $culture = null;
     //go for the GET URL
     if (isset($_GET['lang'])) {
         $culture = $_GET['lang'];
     }
     //set the culture if valid.
     if (!empty($culture) && CultureInfo::validCulture($culture)) {
         $this->Culture = $culture;
     }
 }
 /**
  * Get and set the language setting from/to the cookie.
  * @param TEventParameter event parameter.
  */
 function onLoad($param)
 {
     $app = $this->Application->getGlobalization();
     $cookiename = $this->ID . '_lang';
     if (isset($_COOKIE[$cookiename])) {
         $culture = $_COOKIE[$cookiename];
         if (CultureInfo::validCulture($culture)) {
             $app->Culture = $culture;
         }
     }
     $settings = $this->getSettings();
     $app->Culture = $settings['lang'];
     setcookie($cookiename, $app->Culture, time() + 604800);
     parent::onLoad($param);
 }
 /**
  * @static
  * @return array
  */
 public static function getAvailableCultures()
 {
     //FCKeditor's available languages
     $fck = self::getFCKeditorsLanguages();
     //Prado's available languages
     $prado = CultureInfo::getCultures();
     //Gets the intersection through comparison
     $intersection = array();
     foreach ($prado as $p) {
         foreach ($fck as $f) {
             if (eregi("^" . sql_regcase($p) . "\$", str_replace('-', '_', $f))) {
                 $intersection[$p] = $f;
             }
         }
     }
     unset($fck, $prado);
     //Include languages that were not included, but are available.
     $intersection['ja'] = 'jp';
     $intersection['ja_JP'] = 'jp';
     $intersection['ja_JP_TRADITIONAL'] = 'jp';
     return $intersection;
 }
예제 #8
0
파일: Home.php 프로젝트: Nurudeen/prado
 /**
  * Get the localized current culture name.
  * @return string localized curreny culture name.
  */
 public function getCurrentCulture()
 {
     $culture = $this->getApplication()->getGlobalization()->getCulture();
     $cultureInfo = new CultureInfo($culture);
     return $cultureInfo->getNativeName();
 }
예제 #9
0
 /**
  * Gets the default NumberFormatInfo that is culture-independent
  * (invariant).
  * @return NumberFormatInfo default NumberFormatInfo.
  */
 public static function getInvariantInfo($type = NumberFormatInfo::DECIMAL)
 {
     static $invariant;
     if ($invariant === null) {
         $culture = CultureInfo::getInvariantCulture();
         $invariant = $culture->NumberFormat;
         $invariant->setPattern($type);
     }
     return $invariant;
 }
 /**
  * Returns the DateTimeFormatInfo associated with the specified culture.
  * @param CultureInfo the culture that gets the DateTimeFormat property.
  * @return DateTimeFormatInfo DateTimeFormatInfo for the specified 
  * culture. 
  */
 function getInstance($culture = null)
 {
     if ($culture instanceof CultureInfo) {
         return $culture->DateTimeFormat;
     } else {
         if (is_string($culture)) {
             $cultureInfo = new CultureInfo($culture);
             return $cultureInfo->DateTimeFormat;
         } else {
             $cultureInfo = CultureInfo::getInvariantCulture();
             return $cultureInfo->DateTimeFormat;
         }
     }
 }
예제 #11
0
 /**
  * Gets the list of supported cultures filtered by the specified 
  * culture type. This is an EXPENSIVE function, it needs to traverse
  * a list of ICU files in the data directory.
  * This function can be called statically.
  * @param int culture type, CultureInfo::ALL, CultureInfo::NEUTRAL
  * or CultureInfo::SPECIFIC.
  * @return array list of culture information available. 
  */
 static function getCultures($type = CultureInfo::ALL)
 {
     $dataDir = CultureInfo::dataDir();
     $dataExt = CultureInfo::fileExt();
     $dir = dir($dataDir);
     $neutral = array();
     $specific = array();
     while (false !== ($entry = $dir->read())) {
         if (is_file($dataDir . $entry) && substr($entry, -4) == $dataExt && $entry != 'root' . $dataExt) {
             $culture = substr($entry, 0, -4);
             if (strlen($culture) == 2) {
                 $neutral[] = $culture;
             } else {
                 $specific[] = $culture;
             }
         }
     }
     $dir->close();
     switch ($type) {
         case CultureInfo::ALL:
             $all = array_merge($neutral, $specific);
             sort($all);
             return $all;
             break;
         case CultureInfo::NEUTRAL:
             return $neutral;
             break;
         case CultureInfo::SPECIFIC:
             return $specific;
             break;
     }
 }
예제 #12
0
 /**
  * @covers Xmlnuke\Core\Locale\CultureInfo::getDoubleVal
  * @todo   Implement testGetDoubleVal().
  */
 public function testGetDoubleVal()
 {
     $this->assertEquals(1234.56, $this->object->getDoubleVal('1234.56'));
     $this->assertEquals(1234.0, $this->object->getDoubleVal('1234,56'));
     $this->assertEquals(1234.0, $this->object->getDoubleVal('1234'));
 }
예제 #13
0
 function test_missing_english_names_returns_culture_code()
 {
     $culture = new CultureInfo('iw');
     $this->assertEquals($culture->getEnglishName(), 'iw');
 }