function test_getLanguageId_uc() { $h = fbISO639::getnametoidhash(); foreach ($h as $name => $id) { $name = strtoupper($name); $rv = fbISO639::getLanguageId($name); $this->assertEquals($id, $rv, "name={$name}"); } }
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); }