ZF2-161: InvalidArgumentException in CLDR lookup functions

Description

Version: Github download 2012-02-11

Sample code:

echo \Zend\Locale\Locale::getTranslation('de', 'language', 'de'); echo \Zend\Locale\Data\Cldr::getContent('ar', 'defaultnumberingsystem');

Expected output:

"Deutsch" "arab"

Actual output:

Uncaught exception 'Zend\Locale\Exception\InvalidArgumentException' with message 'Unknown detail (language) for parsing locale data.' Uncaught exception 'Zend\Locale\Exception\InvalidArgumentException' with message 'Unknown detail (defaultnumberingsystem) for parsing locale data.'

These are the ZF2 equivalents of ZF1 functions, both of which produce the expected output:

Zend_Locale::getTranslation(); Zend_Locale_Data::getContent();

Possible solution:

The function \Zend\Locale\Data\Cldr::getContent() has a long switch statement (lines 900-1300) containing each of the possible CLDR lookups. It does not have the cases for 'language' or 'defaultnumberingsystem'. These could be added as follows:

case 'language': $temp = self::_getFile('main/' . $locale, '/ldml/localeDisplayNames/languages/language[@type=\'' . $value . '\']'); break;

case 'defaultnumberingsystem': $temp = self::_getFile('main/' . $locale, '/ldml/numbers/defaultNumberingSystem'); break;

Comments

This break was introduced in the following commit https://github.com/zendframework/zf2/…

Now I'm studying the reasons behind this.

Finally this will not be fixed because there is a plan to remove this component.

With beta5 a new component will be released to cover this features.

As workaround you can use the functions provided by AbstractLocale (getDisplayLanguage, getDisplayScript, getDisplayRegion)