function getNearestLocales($locales) { fbDebug::enter(); static $locale_map; static $available_locales; if (!$available_locales) { $available_locales =& fbLocale::getAvailableLocales(); } // \todo get serialize working $locale_key = is_array($locales) ? serialize($locales) : $locales; fbDebug::dump($locale_key, '$locale_key'); if (!isset($locale_map[$locale_key])) { if (is_array($locales)) { foreach ($locales as $locale) { $locale_map[$locale_key] = fbLocale::getNearestLocales($locale); if ($locale_map[$locale_key]) { fbDebug::dump($locale_map[$locale_key], '$locale_map[$locale_key]'); return $locale_map[$locale_key]; } } fbDebug::dump($locale_map[$locale_key], '$locale_map[$locale_key]'); return $locale_map[$locale_key]; } if (isset($available_locales[$locale_key])) { $locale_map[$locale_key] = $locale_key; fbDebug::dump($locale_map[$locale_key], '$locale_map[$locale_key]'); return $locale_map[$locale_key]; } else { $language = substr($locale_key, 0, 2); fbDebug::dump($language, '$language'); foreach ($available_locales as $locale => $available_language) { fbDebug::dump($locale, '$locale'); fbDebug::dump($available_language, '$available_language'); if (strcasecmp($language, $available_language) == 0) { $locale_map[$locale_key] = $locale; fbDebug::dump($locale_map[$locale_key], '$locale_map[$locale_key]'); return $locale_map[$locale_key]; } } $locale_map[$locale_key] = false; fbDebug::dump($locale_map[$locale_key], '$locale_map[$locale_key]'); } } fbDebug::dump($locale_map[$locale_key], '$locale_map[$locale_key]'); fbDebug::leave($locale_map[$locale_key]); return $locale_map[$locale_key]; }
echo "setlocale(LC_ALL, '$locale')=",setlocale(LC_ALL, $locale),"\n"; echo 'setlocale(0, 0)=', setlocale(0, 0),"\n"; echo 'strftime(\'%A %e %B %Y\', mktime (0, 0, 0, 12, 22, 1978))=',strftime('%A %e %B %Y', mktime (0, 0, 0, 12, 22, 1978)),"\n"; echo 'gettext("24 hours")=',gettext("24 hours"),"\n"; echo 'gettext(\'24 hours\')=',gettext('24 hours'),"\n"; // _() as in alias for gettext() echo '_("24 hours")=',_("24 hours"),"\n"; echo '_(\'24 hours\')=',_('24 hours'),"\n"; //echo 'fbLocale::parseAcceptLanguages='; //print_r(fbLocale::parseAcceptLanguages()); */ // echo 'fbLocale::parseAcceptLanguages='; // print_r(fbLocale::parseAcceptLanguages()); // echo "\n"; echo 'fbLocale::getNearestLocales(fbLocale::parseAcceptLanguages())='; print_r(fbLocale::getNearestLocales(fbLocale::parseAcceptLanguages())); print "\n"; echo 'fbLocale::getAvailableLocales='; print_r(fbLocale::getAvailableLocales()); echo '$long_month_names_hash ='; print_r($long_month_names_hash); echo '$long_weekday_names_hash ='; print_r($long_weekday_names_hash); /* $locales = fbLocaleWindows::mimeToWindowsLocaleMap(); foreach ($locales as $iso_locale => $country_name) { $nearest_locale = fbLocale::getNearestLocale($iso_locale); $nearest_country_name = ''; printf("%-10s %-30s %-10s %-30s\n", $iso_locale, $country_name, $nearest_locale, $nearest_country_name); }
function _loadData() { fbDebug::enter(); $text_domain =& fbGettext::_text_domain(); $domain = fbGettext::_domain(); static $original_locale = null; fbDebug::dump($text_domain, 'text_domain'); fbDebug::dump($domain, 'domain'); // \todo fixme $dir = isset($text_domain[$domain]) ? $text_domain[$domain] . '/' : FREEBEER_BASE . '/lib/locale/'; $locale = fbLocale::getLocale(); fbDebug::dump($locale, 'locale'); assert('strlen($locale)'); if ($original_locale === null) { $original_locale = $locale; } $translation_map =& fbGettext::_translation_map(); foreach ($translation_map as $key => $value) { unset($translation_map[$key]); } if ($locale == $original_locale) { return true; } if (!@is_dir($dir)) { trigger_error(sprintf("Directory '%s' not found", $dir), E_USER_WARNING); return false; } $file = $dir . $locale . '.po'; fbDebug::dump($file, 'file'); while (!is_file($file)) { if (strpos($file, '_') === false) { $file = $dir . $locale . '_' . strtoupper($locale) . '.po'; if (is_file($file) && is_readable($file)) { break; } } $nearest_locales = fbLocale::getNearestLocales($locale); if (!is_array($nearest_locales)) { $nearest_locales = array($nearest_locales); } foreach ($nearest_locales as $nearest_locale) { //trigger_error(sprintf('File \'%s\' not found', $file), E_USER_NOTICE); $file = $dir . $nearest_locale . '.po'; if (is_file($file) && is_readable($file)) { break 2; } if (strpos($file, '_') === false) { $file = $dir . $nearest_locale . '_' . strtoupper($nearest_locale) . '.po'; if (is_file($file) && is_readable($file)) { break 2; } } } return false; } $f = file($file); if (!$f) { trigger_error(sprintf('File \'%s\' is not readable', $file), E_USER_WARNING); return false; } foreach ($f as $l) { if (preg_match('|msgid\\s+["\'](.*)["\']|U', $l, $matches)) { $msgid = $matches[1]; continue; } if (preg_match('|msgstr\\s+["\'](.*)["\']|U', $l, $matches)) { if ($msgid) { $translation_map[$msgid] = $matches[1]; $msgid = ''; } continue; } } fbDebug::dump($translation_map, 'translation_map'); return true; }