The reason for this behaviour can be found in the manual for Zend_Currency which causes the problem as you already noted:

http://framework.zend.com/manual/en/zend.currency.usage.html...
"Note that Zend_Currency only accepts locales which include a region. This means that all locales that only include a language will result in an exception. For example the locale en will cause an exception to be thrown whereas the locale en_US will return USD as currency."

The reason is that "en" defines about 30 different currencies... a language alone has no connection to a country, and currencies are defined by countries, not by languages.

You should also note that ZF has a minimum requirement of ZF 5.2.4 as 5.2.0 introduced several problems within PHP itself.

For a correct usage of Currency you must check if your user sets a country or not. Because when your user sets "fr" it would still be ok for your code, but not for Zend_Currency.

See Zend_Locale for how to detect and set region codes.

Greetings
Thomas Weidner, I18N Team Leader, Zend Framework
http://www.thomasweidner.com

----- Original Message ----- From: "Mr. Eric Eugene Naujock" <[email protected]>
To: <[email protected]>
Sent: Tuesday, April 21, 2009 8:31 PM
Subject: [fw-general] Issues with Zend_Locale and Language Selection.


I am finding that for some reason I am getting error messages in my logs that read as such.

No region found within the locale 'en'

When I decided to take a look I set my browser the use a locale first of 'en' then 'en_US'. When I do so I get errors in my logs that would read like above. I also am getting blank pages with no content. Looking around it would seem that the Zend_Currency seems to be causing the issue.

I am running Zend Framework 1.7.6 with php 5.2.0 latest patch version from my distribution of Ubuntu 4

According to the documentation the code I have in my bootstrap should handle the issue of the bad language code but for some reason it doesn't.

try {
    $locale = new Zend_Locale('auto');
} catch (Zend_Locale_Exception $e) {
    $locale = new Zend_Locale('en_US');
}
Zend_Registry::set('locale',$locale);
Zend_Registry::set('Zend_Locale', $locale);

I have also tried to use the following in my bootstrap and that has no better results. From what I understand after 1.5 the following seems to be the recommended way to go.

Zend_Locale::setDefault('en_US');
$locale = new Zend_Locale();
Zend_Registry::set('locale',$locale);
Zend_Registry::set('Zend_Locale', $locale);

I still am getting these errors which would lead me to think my guests are getting blank pages if their browser is not set to a locality. How ca I fix this other then to RIP out all the localization attached to currencies. I would rather thy to be nicer to visitors of other languages.

From what I am reading on the site if a language does not have a locality the the library is supposed to select the first locality available. This does not seem to be happening.

Is there a fix for this or do I have to add a bunch of additional try/ catch options to my view scripts?

Reply via email to