| // +---------------------------------------------------------------------------+ require_once 'I18Nv2.php'; /** * Wraps PEAR locale package. * * @package SGL * @author Jacob Singh * @version $Revision: 1.6 $ */ class SGL_Locale { /** * Negotiates the locale from HTTP if necessary. Gets it from _SESSION and database otherwise. * * usage: * * $locale =& SGL_Locale::singleton(); * // setting locale here would override defaults. * * echo $locale->formatCurrency(2000,I18Nv2_CURRENCY_LOCAL); * echo $locale->formatDate(time()); * * @param string $locale Overrides getting the locale from session/usr * @return I18Nv2 Returns a single instance of I18Nv2 */ function &singleton($newLocale = false) { SGL::logMessage(null, PEAR_LOG_DEBUG); static $locale; if (!isset($locale)) { if ($newLocale) { $locale = &I18Nv2::createLocale($newLocale); } else { // Get the language shortcode from the session $langCode = SGL::getCurrentLang(); $uid = SGL_Session::getUid(); require_once 'I18Nv2/Negotiator.php'; if ($uid && isset($langCode)) { $dbh = &SGL_DB::singleton(); $c = &SGL_Config::singleton(); $conf = $c->getAll(); $country = $dbh->getOne("SELECT country FROM {$conf['table']['user']} WHERE usr_id = ".$uid); $country = strtoupper($country); if (!$country) { $neg = &new I18Nv2_Negotiator(); $country = $neg->getCountryMatch($langCode); } $localeId = empty($country) ? $langCode : $langCode . "_" . $country; } else { $neg = &new I18Nv2_Negotiator(); $localeId = $neg->getLocaleMatch(); } $locale = &I18Nv2::createLocale($localeId); } } return $locale; } function setTimeZone($tzone) { setlocale(LC_TIME, $tzone); @putenv('TZ=' . $tzone); } } // if iconv extension not present, at least fail silently if (!(function_exists('iconv'))) { function iconv($in_charset, $out_charset, $string) { return $string; } } ?>