Zend_Framework - no regions were found in the locale 'zh'

I browsed the Internet and cannot find a solution to the problem that I am facing. I am trying to use Zend_Currency to get currency for China like this:

$currency = new Zend_Currency('CN'); 

However, I keep getting the following error:

 Fatal error: Uncaught exception 'Zend_Currency_Exception' with message 'No region found within the locale 'zh'' in /Library/WebServer/Documents/vendor/zendframework/zendframework1/library/Zend/Currency.php on line 561 

This is a new installation of Zend Framework 1.12.3, and as far as I know, I am not doing anything wrong here. From the error, I see that Zend maps the country code to the locale.

This is a problem since my application relies on getting currency information from the country code. I have no problem with GB, US, etc.

I looked at Zend/Locale/Data and I can confirm that there are locale files zh.xml , zh_CN.xml , but I admit that I am not 100% what I am looking for in everyone!

Does anyone have any idea that this is a problem and how can I fix it?

thanks

EDIT:

This is a change to discuss comments.

It seems that Zend_Locale returns zh if the CN country code is given, rather than the expected string zh_CN . This means that I cannot find anything consistent to go to Zend_Currency to avoid errors.

+6
source share
2 answers

I think this is a bug in Zend, which is incompatible with the CN region.
In fact, if I'm not mistaken, the name of the locale is zh_Hans_CN , and when it manages the CN area, Zend sees if it is part of the $_localeData variable (in the Zend / Locale.php file) and since it is not, it decomposes zh_Hans_CN and saves only zh , he also does not know.

If you want to keep the same principle as $currency = new Zend_Currency('CN');
you can try:

 Zend_Locale::getLocaleToTerritory('CN'); 

will get the correct locale by default. (e.g. 'US' give 'en_US' )
What gives:

 $currency = new Zend_Currency(Zend_Locale::getLocaleToTerritory('CN')); 
+3
source

Try this way;)

 $currency = new Zend_Currency('zh_CN'); 
+1
source

Source: https://habr.com/ru/post/969571/


All Articles