function getCountryNameByHostName($name) { include_once FREEBEER_BASE . '/lib/ISO3166.php'; $cc = fbGeoIP_Free::getCountryIdByHostName($name); $rv = fbISO3166::getCountryName($cc); return $rv ? $rv : $cc; }
function test_getCountryName_uc() { $h = fbISO3166::getidtonamehash(); foreach ($h as $id => $name) { $id = strtoupper($id); $rv = fbISO3166::getCountryName($id); $this->assertEquals($name, $rv, "id={$id}"); } }
//$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 = ''; $short_date = ''; $datetime = ''; $number = ''; $money = ''; $charset = ''; $codepage = '';
function _parseLocale($locale = null) { static $_codepage_to_charset_map = array('1250' => 'ISO8859-2', '1251' => 'ISO8859-5', '1252' => 'ISO8859-1', '1253' => 'ISO8859-1', '1254' => 'ISO8859-9', '1257' => 'ISO8859-13', '1252' => 'ISO885915'); if (is_null($locale)) { $locale = fbLocale::_getLocale(LC_ALL); } $iso_locale = false; $language_id = false; $language = false; $country = false; $country_id = false; $charset = false; $codepage = false; do { $lang = $locale; if (preg_match('/LC_COLLATE=([^;]*)/i', $locale, $matches)) { if ($matches[1] == 'C') { if (preg_match('/LC_CTYPE=([^;]*)/i', $locale, $matches)) { $lang = $matches[1]; } } else { $lang = $matches[1]; } } /// \todo deal with ll-CC if (preg_match('/([^\\._]+)[\\._]*(.*)/i', $lang, $matches)) { $lang = $matches[1]; $coun = $matches[2]; if (preg_match('/([^\\._]+)[\\._]*(.*)/i', $coun, $matches)) { $coun = $matches[1]; $charset = $matches[2]; } } if ($lang == 'C') { return array('locale' => 'C', 'language_id' => '', 'language' => '', 'country_id' => '', 'country' => '', 'charset' => '', 'codepage' => ''); } $language = fbISO639::getLanguageName($lang); if ($language) { $language_id = $lang; } else { $language_id = fbISO639::getLanguageId($lang); if (!$language_id) { trigger_error(sprintf('Language not found: \'%s\'', $lang), E_USER_WARNING); break; } $language = $lang; } $iso_locale = fbString::strtolower($language_id); $country = fbISO3166::getCountryName($coun); if ($country) { $country_id = fbString::strtoupper($coun); } else { $country_id = fbISO3166::getCountryId($coun); if ($coun && !$country_id) { trigger_error(sprintf('Country not found: \'%s\'', $coun), E_USER_WARNING); break; } } $iso_locale .= '_' . fbString::strtoupper($country_id); if ($charset) { $charset = fbString::strtoupper($charset); if (isset($_codepage_to_charset_map[$charset])) { $codepage = $charset; $charset = $_codepage_to_charset_map[$charset]; } else { $_charset_to_codepage_map = array_flip($_codepage_to_charset_map); if (isset($_charset_to_codepage_map[$charset])) { $codepage = $_charset_to_codepage_map[$charset]; } else { trigger_error(sprintf('Charset not found: \'%s\'', $charset), E_USER_NOTICE); break; } } $iso_locale .= '.' . $charset; } } while (false); return array('locale' => $iso_locale, 'language_id' => fbString::strtoupper($language_id), 'language' => $language, 'country_id' => fbString::strtoupper($country_id), 'country' => $country, 'charset' => fbString::strtoupper($charset), 'codepage' => $codepage); }
function getCountryName($id) { $ID_TO_NAME_HASH =& fbISO3166::getIDToNameHash(); $id = strtoupper($id); return isset($ID_TO_NAME_HASH[$id]) ? $ID_TO_NAME_HASH[$id] : false; }