Пример #1
0
function smarty_block_tr($params, $content, &$smarty)
{
    global $_SERVER;
    // < 4.1.0
    static $init;
    static $default_languages = false;
    if (!$init) {
        $init = true;
        fbGettext::init();
        if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
            $default_languages =& fbLocale::parseAcceptLanguages($_SERVER['HTTP_ACCEPT_LANGUAGE']);
        }
    }
    $lang = false;
    extract($params);
    if ($lang) {
        $languages =& fbLocale::parseAcceptLanguages($lang);
    } else {
        $languages = $default_languages;
    }
    /// \todo only switch locales if the current locale is different!
    fbLocale::pushLocale(LC_ALL, $languages);
    $rv = gettext($content);
    fbLocale::popLocale(LC_ALL);
    return $rv;
}
Пример #2
0
$rv = bindtextdomain('freebeer', FREEBEER_BASE . '/lib/locale');
printf("bindtextdomain('freebeer', '%s')=%s\n", FREEBEER_BASE . '/lib/locale', $rv);
$rv = textdomain('freebeer');
echo 'textdomain(\'freebeer\')=', $rv, "\n";
print "<table border='1'>\n<tr>\n<th>\nISO Code\n</th>\n<th>\n_('24 hours')\n</th>\n<th>\nLong Date\n</th>\n<th>\nShort Date\n</th>\n<th>\nDate/Time\n</th>\n<th>\nNumber\n</th>\n<th>\nMoney\n</th>\n<th>\nLong Month Names\n</th>\n<th>\nShort Month Names\n</th>\n<th>\nLong Weekday Names\n</th>\n<th>\nShort Weekday Names\n</th>\n<th>\nLocale\n</th>\n<th>\nCharset\n</th>\n<th>\nCode Page\n</th>\n</tr>\n";
$date = mktime(13, 14, 15, 2, 1, 2003);
//$locales = &fbLocaleWindows::mimeToWindowsLocaleMap();
$locales = fbLocale::getAvailableLocales();
$locales[$default_locale] = $default_locale_name;
$locales['en_US'] = 'English.United States';
$locales['en_GB'] = 'English.United Kingdom';
ksort($locales);
$long_month_names_hash = array();
$long_weekday_names_hash = array();
foreach ($locales as $locale => $language) {
    $rv = fbLocale::pushLocale(LC_ALL, $locale);
    //echo "fbLocale::pushLocale(LC_ALL, $locale) returned '$rv'\n";
    $name = $locale;
    $language_id = substr($locale, 0, 2);
    $language = fbISO639::getLanguageName($language_id);
    $country_id = substr($locale, 3, 2);
    $country = fbISO3166::getCountryName($country_id);
    $id3 = fbISO639_Map::getID3($language_id);
    $language3 = fbISO639_Alpha3::getLanguageName($id3);
    $name .= " ({$language}";
    if ($language3 != $language) {
        $name .= ' [' . $language3 . ']';
    }
    $name .= "/{$country}/{$id3})";
    $string = '<i>Unavailable</i>';
    $long_date = '';
Пример #3
0
 function _getDateNames($format, $locale = null)
 {
     static $rv = array();
     $get_locale = is_null($locale);
     if ($get_locale) {
         $locale = fbLocale::getLocale(LC_TIME);
     }
     if (!isset($rv[$locale])) {
         if (!$get_locale) {
             fbLocale::pushLocale(LC_TIME, $locale);
         }
         $t = array();
         for ($i = 0; $i < 12; ++$i) {
             $date = mktime(0, 0, 0, 1 + $i, 1, 2003);
             $t['B'][] = strftime('%B', $date);
             $t['b'][] = strftime('%b', $date);
         }
         for ($i = 0; $i < 7; ++$i) {
             $date = mktime(0, 0, 0, 11, 9 + $i, 2003);
             // 9-Nov-2003 was a Sunday
             $t['A'][] = strftime('%A', $date);
             $t['a'][] = strftime('%a', $date);
         }
         $rv[$locale] = $t;
         if (!$get_locale) {
             fbLocale::popLocale(LC_TIME);
         }
     }
     return $rv[$locale][$format];
 }
Пример #4
0
 function numberFormat($number, $digits = null, $locale = null)
 {
     fbDebug::enter();
     static $localeconv_cache = array();
     $get_locale = is_null($locale);
     fbDebug::dump($get_locale, '$get_locale');
     if ($get_locale) {
         $locale = fbLocale::getLocale(LC_MONETARY);
         fbDebug::dump($locale, '$locale');
     }
     fbDebug::dump($localeconv_cache, '$localeconv_cache');
     if (!isset($localeconv_cache[$locale])) {
         fbDebug::dump($locale, '$locale');
         if (!$get_locale) {
             $rv = fbLocale::pushLocale(LC_MONETARY, $locale);
             fbDebug::dump($rv, '$rv');
         }
         $_locale = fbLocale::getLocale(LC_MONETARY);
         fbDebug::dump($_locale, '$_locale');
         $localeconv_cache[$locale] = localeconv();
         fbDebug::dump($localeconv_cache[$locale], '$localeconv_cache[$locale]');
         if (!$get_locale) {
             fbLocale::popLocale(LC_MONETARY);
         }
     }
     $lc = $localeconv_cache[$locale];
     fbDebug::dump($lc, '$lc');
     if (is_null($digits)) {
         $digits = $lc['int_frac_digits'];
     }
     $rv = number_format($number, $digits, $lc['mon_decimal_point'], $lc['mon_thousands_sep']);
     $n = strpos($rv, '-');
     if ($n !== false) {
         $rv = str_replace('-', $lc['negative_sign'], $rv);
     }
     fbDebug::leave($rv);
     return $rv;
 }