|
29 | 29 | */ |
30 | 30 | class Zend_Locale |
31 | 31 | { |
| 32 | + /** |
| 33 | + * List of locales that are no longer part of CLDR along with a |
| 34 | + * mapping to an appropriate alternative. |
| 35 | + * |
| 36 | + * @var array |
| 37 | + */ |
| 38 | + private static $_localeAliases = array( |
| 39 | + 'az_AZ' => 'az_Latn_AZ', |
| 40 | + 'bs_BA' => 'bs_Latn_BA', |
| 41 | + 'ha_GH' => 'ha_Latn_GH', |
| 42 | + 'ha_NE' => 'ha_Latn_NE', |
| 43 | + 'ha_NG' => 'ha_Latn_NG', |
| 44 | + 'kk_KZ' => 'kk_Cyrl_KZ', |
| 45 | + 'ks_IN' => 'ks_Arab_IN', |
| 46 | + 'mn_MN' => 'mn_Cyrl_MN', |
| 47 | + 'ms_BN' => 'ms_Latn_BN', |
| 48 | + 'ms_MY' => 'ms_Latn_MY', |
| 49 | + 'ms_SG' => 'ms_Latn_SG', |
| 50 | + 'pa_IN' => 'pa_Guru_IN', |
| 51 | + 'pa_PK' => 'pa_Arab_PK', |
| 52 | + 'shi_MA' => 'shi_Latn_MA', |
| 53 | + 'sr_BA' => 'sr_Latn_BA', |
| 54 | + 'sr_ME' => 'sr_Latn_ME', |
| 55 | + 'sr_RS' => 'sr_Latn_RS', |
| 56 | + 'sr_XK' => 'sr_Latn_XK', |
| 57 | + 'tg_TJ' => 'tg_Cyrl_TJ', |
| 58 | + 'tzm_MA' => 'tzm_Latn_MA', |
| 59 | + 'uz_AF' => 'uz_Arab_AF', |
| 60 | + 'uz_UZ' => 'uz_Latn_UZ', |
| 61 | + 'vai_LR' => 'vai_Latn_LR', |
| 62 | + 'zh_CN' => 'zh_Hans_CN', |
| 63 | + 'zh_HK' => 'zh_Hans_HK', |
| 64 | + 'zh_MO' => 'zh_Hans_MO', |
| 65 | + 'zh_SG' => 'zh_Hans_SG', |
| 66 | + 'zh_TW' => 'zh_Hant_TW', |
| 67 | + ); |
| 68 | + |
32 | 69 | /** |
33 | 70 | * Class wide Locale Constants |
34 | 71 | * |
@@ -1266,6 +1303,12 @@ public function setLocale($locale = null) |
1266 | 1303 | $locale = self::_prepareLocale($locale); |
1267 | 1304 |
|
1268 | 1305 | if (isset(self::$_localeData[(string) $locale]) === false) { |
| 1306 | + // Is it an alias? If so, we can use this locale |
| 1307 | + if (isset(self::$_localeAliases[$locale]) === true) { |
| 1308 | + $this->_locale = $locale; |
| 1309 | + return; |
| 1310 | + } |
| 1311 | + |
1269 | 1312 | $region = substr((string) $locale, 0, 3); |
1270 | 1313 | if (isset($region[2]) === true) { |
1271 | 1314 | if (($region[2] === '_') or ($region[2] === '-')) { |
@@ -1878,4 +1921,38 @@ public static function getOrder($order = null) |
1878 | 1921 |
|
1879 | 1922 | return $languages; |
1880 | 1923 | } |
| 1924 | + |
| 1925 | + /** |
| 1926 | + * Is the given locale in the list of aliases? |
| 1927 | + * |
| 1928 | + * @param string|Zend_Locale $locale Locale to work on |
| 1929 | + * @return boolean |
| 1930 | + */ |
| 1931 | + public static function isAlias($locale) |
| 1932 | + { |
| 1933 | + if ($locale instanceof Zend_Locale) { |
| 1934 | + $locale = $locale->toString(); |
| 1935 | + } |
| 1936 | + |
| 1937 | + return isset(self::$_localeAliases[$locale]); |
| 1938 | + } |
| 1939 | + |
| 1940 | + /** |
| 1941 | + * Return an alias' actual locale. |
| 1942 | + * |
| 1943 | + * @param string|Zend_Locale $locale Locale to work on |
| 1944 | + * @return string |
| 1945 | + */ |
| 1946 | + public static function getAlias($locale) |
| 1947 | + { |
| 1948 | + if ($locale instanceof Zend_Locale) { |
| 1949 | + $locale = $locale->toString(); |
| 1950 | + } |
| 1951 | + |
| 1952 | + if (isset(self::$_localeAliases[$locale]) === true) { |
| 1953 | + return self::$_localeAliases[$locale]; |
| 1954 | + } |
| 1955 | + |
| 1956 | + return (string) $locale; |
| 1957 | + } |
1881 | 1958 | } |
0 commit comments