/** * Change the globalization culture using value from request "lang" parameter. */ public function __construct() { parent::__construct(); $lang = $this->Request['lang']; $info = new CultureInfo(); if ($info->validCulture($lang)) { //only valid lang is permitted $this->getApplication()->getGlobalization()->setCulture($lang); } }
/** * 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; } }
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); } } }
/** * 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); }
/** * 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); }