/** * __construct * * Set locale for gettext * * @access public * @return void */ public function __construct() { parent::__construct(); $baseLocaleDir = FRAMEWORK_BASE_PATH . '/'; $baseLocaleDir .= (string) Framework::$site->config->user->userLocaleDir; I18Nv2::setLocale($this->locale); bindtextdomain("messages", $baseLocaleDir); textdomain("messages"); }
/** * __construct * * Set locale for gettext * * @access public * @return void */ public function __construct() { parent::__construct(); $baseLocaleDir = FRAMEWORK_BASE_PATH . '/'; $baseLocaleDir .= (string) Framework::$site->config->user->userLocaleDir; // Fix for missing _COUNTRY in negotiated locale string if (strlen($this->locale) == 2) { $this->locale = $this->locale . '_' . strtoupper($this->locale); } I18Nv2::setLocale($this->locale); bindtextdomain("messages", $baseLocaleDir); textdomain("messages"); }
/** * Sets the current lang * * @param string $langID language ID * * @return array language data */ function setLang($langID) { if (!PEAR::isError($langData = parent::setLang($langID))) { I18Nv2::setLocale($langID); } return $langData; }
/** * Get current/prior Locale * * @static * @access public * @return mixed last locale as string or array * @param int $prior if 0, the current otherwise n prior to current * @param bool $part true|all|0=locale|1=language|2=syslocale */ function lastLocale($prior = 0, $part = 0) { $last = I18Nv2::getStaticProperty('last'); if (!isset($last)) { return I18Nv2::setLocale(); } if (!isset($last[$prior])) { return null; } if ($part === true || $part == 'all') { return $last[$prior]; } return $last[$prior][$part]; }
/** * Initialize * * @access public * @return void */ function initialize($locale) { $this->initialized = $locale; $this->usedLocale = I18Nv2::setLocale($locale); $jan = $mon = mktime(1, 1, 1, 1, 1, 1990); $feb = $tue = mktime(1, 1, 1, 2, 6, 1990); $mar = $wed = mktime(1, 1, 1, 3, 7, 1990); $apr = $thu = mktime(1, 1, 1, 4, 5, 1990); $may = $fri = mktime(1, 1, 1, 5, 4, 1990); $jun = $sat = mktime(1, 1, 1, 6, 2, 1990); $jul = $sun = mktime(1, 1, 1, 7, 1, 1990); $aug = mktime(1, 1, 1, 8, 1, 1990); $sep = mktime(1, 1, 1, 9, 1, 1990); $oct = mktime(1, 1, 1, 10, 1, 1990); $nov = mktime(1, 1, 1, 11, 1, 1990); $dec = mktime(1, 1, 1, 12, 1, 1990); if (!$this->loadCache($this->usedLocale)) { $this->days = array(strftime('%A', $sun), strftime('%A', $mon), strftime('%A', $tue), strftime('%A', $wed), strftime('%A', $thu), strftime('%A', $fri), strftime('%A', $sat)); $this->abbrDays = array(strftime('%a', $sun), strftime('%a', $mon), strftime('%a', $tue), strftime('%a', $wed), strftime('%a', $thu), strftime('%a', $fri), strftime('%a', $sat)); $this->months = array(strftime('%B', $jan), strftime('%B', $feb), strftime('%B', $mar), strftime('%B', $apr), strftime('%B', $may), strftime('%B', $jun), strftime('%B', $jul), strftime('%B', $aug), strftime('%B', $sep), strftime('%B', $oct), strftime('%B', $nov), strftime('%B', $dec)); $this->abbrMonths = array(strftime('%b', $jan), strftime('%b', $feb), strftime('%b', $mar), strftime('%b', $apr), strftime('%b', $may), strftime('%b', $jun), strftime('%b', $jul), strftime('%b', $aug), strftime('%b', $sep), strftime('%b', $oct), strftime('%b', $nov), strftime('%b', $dec)); $info = I18Nv2::getInfo(); /* * The currency symbol is old shit on Win2k, though. * Some get extended/overwritten with other local conventions. */ $this->currencyFormats = array(I18Nv2_CURRENCY_LOCAL => array($info['currency_symbol'], $info['int_frac_digits'], $info['mon_decimal_point'], $info['mon_thousands_sep'], $info['negative_sign'], $info['positive_sign'], $info['n_cs_precedes'], $info['p_cs_precedes'], $info['n_sep_by_space'], $info['p_sep_by_space'], $info['n_sign_posn'], $info['p_sign_posn']), I18Nv2_CURRENCY_INTERNATIONAL => array($info['int_curr_symbol'], $info['int_frac_digits'], $info['mon_decimal_point'], $info['mon_thousands_sep'], $info['negative_sign'], $info['positive_sign'], $info['n_cs_precedes'], $info['p_cs_precedes'], true, true, $info['n_sign_posn'], $info['p_sign_posn'])); $this->numberFormats = array(I18Nv2_NUMBER_FLOAT => array($info['frac_digits'], $info['decimal_point'], $info['thousands_sep']), I18Nv2_NUMBER_INTEGER => array('0', $info['decimal_point'], $info['thousands_sep'])); $this->loadExtension(); if (!count($this->dateTimeFormats)) { $this->dateTimeFormats = array(I18Nv2_DATETIME_SHORT => $this->dateFormats[I18Nv2_DATETIME_SHORT] . ', ' . $this->timeFormats[I18Nv2_DATETIME_SHORT], I18Nv2_DATETIME_MEDIUM => $this->dateFormats[I18Nv2_DATETIME_MEDIUM] . ', ' . $this->timeFormats[I18Nv2_DATETIME_MEDIUM], I18Nv2_DATETIME_DEFAULT => $this->dateFormats[I18Nv2_DATETIME_DEFAULT] . ', ' . $this->timeFormats[I18Nv2_DATETIME_DEFAULT], I18Nv2_DATETIME_LONG => $this->dateFormats[I18Nv2_DATETIME_LONG] . ', ' . $this->timeFormats[I18Nv2_DATETIME_LONG], I18Nv2_DATETIME_FULL => $this->dateFormats[I18Nv2_DATETIME_FULL] . ', ' . $this->timeFormats[I18Nv2_DATETIME_FULL]); } $this->updateCache($this->usedLocale); } $this->setDefaults(); if ($this->paranoid) { setlocale(LC_ALL, 'C'); } return $this->usedLocale; }
<?php /** * Setting a locale * ================ * * Because Un*x and Windows use different locale codes, PHPs setLocale() is not * easily portable - I18Nv2::setLocale() attempts to provide this portability. * * With I18Nv2 you can use standard locale codes like 'en_US' on both, Linux * and Windows, though the list is far not complete yet, so if you stumble * over a not covered locale (I18Nv2::$locales in I18Nv2::_main()), just drop * a mail to <mike(@)php.net> with the missing locale and its corresponding * Win32 code. * * $Id: setting_a_locale.php,v 1.1 2004/05/03 15:02:17 mike Exp $ */ require_once 'I18Nv2.php'; $locale = 'en_US'; if (!I18Nv2::setLocale($locale)) { die("Locale '{$locale}' not available!\n"); }
<?php /** * Retrieving locale conventions * ============================= * * I18Nv2 holds locale conventions returned by localeConv() stored statically, * so they are easily accessible through I18Nv2::getInfo(). Have a look at * the documentation of PHPs localeConv() for all available information. * * $Id: retrieving_locale_conventions.php,v 1.1 2004/05/03 15:02:17 mike Exp $ */ require_once 'I18Nv2.php'; I18Nv2::setLocale('fr'); $dec_point = I18Nv2::getInfo('decimal_point'); echo "The decimal point for the french locale is '{$dec_point}'.\n"; echo "I18Nv2::getInfo() called without parameter returns all available information:\n"; print_r(I18Nv2::getInfo());
/** * setLocale * * Set Locate info using I18Nv2_Negotiator * * @access protected * @return void */ protected function setLocale() { // Not using negotiation for the time being, static selection only // $neg = &new I18Nv2_Negotiator; // I18Nv2::setLocale($neg->getLocaleMatch()); if (isset($_GET['language'])) { $array = $this->xmlObjToArray($this->languages->xpath('language'), 'name'); if (in_array($_GET['language'], $array)) { $_SESSION['language'] = $_GET['language']; } } // print_r($_GET['language']);exit; if (isset($_SESSION['language'])) { I18Nv2::setLocale($_SESSION['language']); bindtextdomain("messages", "./locale"); bind_textdomain_codeset("messages", 'UTF-8'); textdomain("messages"); } }
/** * setLocale * * Set Locate info using I18Nv2_Negotiator * * @access protected * @return void */ protected function setLocale() { $neg =& new I18Nv2_Negotiator(); I18Nv2::setLocale($neg->getLocaleMatch()); bindtextdomain("messages", "./locale"); bind_textdomain_codeset("messages", 'UTF-8'); textdomain("messages"); }