Skip to content
This repository was archived by the owner on Oct 2, 2019. It is now read-only.

Commit 4261557

Browse files
committed
Extends Zend_Locale_Data::getContent for reading parent locales
1 parent d036788 commit 4261557

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

library/Zend/Locale/Data.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,13 @@ public static function getContent($locale, $path, $value = false)
14741474
$temp = self::_getFile($locale, '/ldml/units/unitLength/unit[@type=\'' . $value[0] . '\']/unitPattern[@count=\'' . $value[1] . '\']', '');
14751475
break;
14761476

1477+
case 'parentlocale':
1478+
if (false === $value) {
1479+
$value = $locale;
1480+
}
1481+
$temp = self::_getFile('supplementalData', "/supplementalData/parentLocales/parentLocale[contains(@locales, '" . $value . "')]", 'parent', 'parent');
1482+
break;
1483+
14771484
default :
14781485
require_once 'Zend/Locale/Exception.php';
14791486
throw new Zend_Locale_Exception("Unknown detail ($path) for parsing locale data.");

tests/Zend/Locale/DataTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7254,4 +7254,28 @@ public function testCreateValidCacheIdsInGetListMethod()
72547254
$this->fail($e->getMessage());
72557255
}
72567256
}
7257+
7258+
/**
7259+
* @group GH-516
7260+
*/
7261+
public function testGetParentLocale()
7262+
{
7263+
// Tests only with locale
7264+
$result = Zend_Locale_Data::getContent('pa_Arab', 'parentlocale');
7265+
$this->assertEquals('root', $result);
7266+
$result = Zend_Locale_Data::getContent('en_CK', 'parentlocale');
7267+
$this->assertEquals('en_001', $result);
7268+
$result = Zend_Locale_Data::getContent('en_JE', 'parentlocale');
7269+
$this->assertEquals('en_GB', $result);
7270+
$result = Zend_Locale_Data::getContent('es_AR', 'parentlocale');
7271+
$this->assertEquals('es_419', $result);
7272+
$result = Zend_Locale_Data::getContent('pt_CV', 'parentlocale');
7273+
$this->assertEquals('pt_PT', $result);
7274+
$result = Zend_Locale_Data::getContent('zh_Hant_MO', 'parentlocale');
7275+
$this->assertEquals('zh_Hant_HK', $result);
7276+
7277+
// Test with value
7278+
$result = Zend_Locale_Data::getContent('de_DE', 'parentlocale', 'zh_Hant_MO');
7279+
$this->assertEquals('zh_Hant_HK', $result);
7280+
}
72577281
}

0 commit comments

Comments
 (0)