Skip to content

Commit 8391f08

Browse files
committed
Aliases for Zend_Locale
Provide aliases in Zend_Locale for locales that no longer exist in CLDR. This allows applications using valid CLDR locale names up to 1.12.3 to continue to work as expected.
1 parent 5e6b115 commit 8391f08

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

Locale.php

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,43 @@
2929
*/
3030
class Zend_Locale
3131
{
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+
3269
/**
3370
* Class wide Locale Constants
3471
*
@@ -1266,6 +1303,12 @@ public function setLocale($locale = null)
12661303
$locale = self::_prepareLocale($locale);
12671304

12681305
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+
12691312
$region = substr((string) $locale, 0, 3);
12701313
if (isset($region[2]) === true) {
12711314
if (($region[2] === '_') or ($region[2] === '-')) {
@@ -1878,4 +1921,38 @@ public static function getOrder($order = null)
18781921

18791922
return $languages;
18801923
}
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+
}
18811958
}

Locale/Data.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ private static function _checkLocale($locale)
292292
throw new Zend_Locale_Exception("Locale (" . (string) $locale . ") is a unknown locale");
293293
}
294294

295+
if (Zend_Locale::isAlias($locale)) {
296+
// Return a valid CLDR locale so that the XML file can be loaded.
297+
return Zend_Locale::getAlias($locale);
298+
}
295299
return (string) $locale;
296300
}
297301

0 commit comments

Comments
 (0)