I've had a look around the Internet and can't seem to find a solution to the problem I'm experiencing. I'm trying to use Zend_Currency to get the currency for China like so:
$currency = new Zend_Currency('CN');
However, I keep receiving 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 on a fresh install of Zend Framework 1.12.3, and as far as I'm aware I'm not doing anything incorrect here. From the error I can see that Zend has matched the country code to the locale.
This is a problem as my application relies on obtaining currency information from a country code. I have no issues with GB, US etc.
I've had a look in Zend/Locale/Data
and can confirm the zh.xml
, zh_CN.xml
locale files are there, but I'll admit I'm not 100% what I'm looking for in each!
Anyone have any ideas about what the issue is and how I might go about fixing it?
Thanks
EDIT:
This is an edit to reflect comment discussion.
It seems that Zend_Locale returns zh
when given the country code CN
, rather than the expected string zh_CN
. This means that I am unable to find anything consistent that I can pass to Zend_Currency to avoid errors.
I think this is a bug in Zend mismanaging 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
region Zend see if it is part of the variable $_localeData
(in Zend/Locale.php file) and as this is not the case, it decomposes zh_Hans_CN
and keeps only zh
he does not know either.
If you want to keep the same principle as $currency = new Zend_Currency('CN');
you can try it:
Zend_Locale::getLocaleToTerritory('CN');
will retrieve the correct locale by default. (like 'US'
give 'en_US'
)
Which gives:
$currency = new Zend_Currency(Zend_Locale::getLocaleToTerritory('CN'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With