<?php // $CVSHeader: _freebeer/www/demo/Locale.php,v 1.2 2004/03/07 17:51:33 ross Exp $ // Copyright (c) 2002-2004, Ross Smith. All rights reserved. // Licensed under the BSD or LGPL License. See license.txt for details. require_once './_demo.php'; echo html_header_demo('fbLocale Class'); echo "<pre>\n"; require_once FREEBEER_BASE . '/lib/Locale.php'; //exit; $iso_codes = array('it_IT' => 'Italian', 'fr_FR' => 'French', 'es_ES' => 'Spanish', 'nl_NL' => 'Dutch', 'en_US' => 'English', 'pt_PT' => 'Portuguese'); echo "fbLocale::getLocale(LC_ALL)=", fbLocale::getLocale(LC_ALL), "\n"; foreach ($iso_codes as $iso_code => $language) { // putenv('LANG=' . $iso_code); fbLocale::setLocale(LC_ALL, $iso_code); /* // \todo convert to one function! putenv('LANG=' . $iso_code); if (preg_match('/^win/i', PHP_OS)) { $rv = setlocale(LC_ALL, $language); } else { $rv = setlocale(LC_ALL, $iso_code); } */ printf("%-12s: %s\n", $language, strftime("%A %a %B %b %c\n")); fbLocale::setLocale(LC_ALL, 'en_US'); } ?> </pre> <address>
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]; }
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; }
$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 = ''; $short_date = ''; $datetime = ''; $number = ''; $money = ''; $charset = ''; $codepage = ''; $locale_name = fbLocale::getLocale(); $long_month_names = ' '; $short_month_names = ' '; $long_weekday_names = ' '; $short_weekday_names = ' '; if ($locale == $default_locale || $locale_name != $default_locale_name) { $string = _('24 hours'); $long_date = fbDateTime::getLongDate($date); $short_date = fbDateTime::getShortDate($date); $datetime = strftime('%c', $date); $amount = -1234567.89; $number = fbLocale::numberFormat($amount, 2); if (function_exists('money_format')) { $money = money_format('%i', $amount) . "<br />\n" . money_format('%n', $amount); } $charset = fbLocale::getCharset();
function gettext($message) { fbDebug::enter(); static $current_locale = null; $locale = fbLocale::getLocale(); if ($locale != $current_locale) { fbGettext::_loadData(); $current_locale = $locale; } $translation_map =& fbGettext::_translation_map(); fbDebug::dump($translation_map, 'translation_map'); if (isset($translation_map[$message])) { return $translation_map[$message]; } return $message; }