The API of Zend_Locale
has changed from time to time.
If you started to use Zend_Locale
and its subcomponents
in earlier versions follow the guidelines below to migrate your scripts to
use the new API.
Some specialized translation methods have been depreciated because they duplicate existing behaviour. Note that the old methods will still work, but a user notice is triggered which describes the new call. The methods will be erased with 2.0. See the following list for old and new method call.
表 31.10. List of measurement types
Old call | New call |
---|---|
getLanguageTranslationList($locale) | getTranslationList('language', $locale) |
getScriptTranslationList($locale) | getTranslationList('script', $locale) |
getCountryTranslationList($locale) | getTranslationList('territory', $locale, 2) |
getTerritoryTranslationList($locale) | getTranslationList('territory', $locale, 1) |
getLanguageTranslation($value, $locale) | getTranslation($value, 'language', $locale) |
getScriptTranslation($value, $locale) | getTranslation($value, 'script', $locale) |
getCountryTranslation($value, $locale) | getTranslation($value, 'country', $locale) |
getTerritoryTranslation($value, $locale) | getTranslation($value, 'territory', $locale) |
According to the coding standards isLocale() had to be changed to return a boolean. In previous releases a string was returned on success. For release 1.7 a compatibility mode has been added which allows to use the old behaviour of a returned string, but it triggers a user warning to mention you to change to the new behaviour. The rerouting which the old behaviour of isLocale() could have done is no longer neccessary as all I18N will now process a rerouting themself.
To migrate your scripts to the new API, simply use the method as shown below.
例 31.50. How to change isLocale() from 1.6 to 1.7
// Example for 1.6 if ($locale = Zend_Locale::isLocale($locale)) { // do something } // Same example for 1.7 // You should change the compatiblity mode to prevent user warnings // But you can do this in your bootstrap Zend_Locale::$compatibilityMode = false; if (Zend_Locale::isLocale($locale)) { }
Note that you can use the second parameter to see if the locale is correct without processing a rerouting.
// Example for 1.6 if ($locale = Zend_Locale::isLocale($locale, false)) { // do something } // Same example for 1.7 // You should change the compatiblity mode to prevent user warnings // But you can do this in your bootstrap Zend_Locale::$compatibilityMode = false; if (Zend_Locale::isLocale($locale, false)) { if (Zend_Locale::isLocale($locale, true)) { // no locale at all } // original string is no locale but can be rerouted }
The meaning of the getDefault() method has been change due to the fact that we integrated a framework locale which can be set with setDefault(). It does no longer return the locale chain but only the set framework locale.
To migrate your scripts to the new API, simply use the method as shown below.
例 31.51. How to change getDefault() from 1.6 to 1.7
// Example for 1.6 $locales = $locale->getDefault(Zend_Locale::BROWSER); // Same example for 1.7 // You should change the compatiblity mode to prevent user warnings // But you can do this in your bootstrap Zend_Locale::$compatibilityMode = false; $locale = Zend_Locale::getOrder(Zend_Locale::BROWSER);
Note that the second parameter of the old getDefault() implementation is not available anymore, but the returned values are the same.
![]() |
注意 |
---|---|
Per default the old behaviour is still active, but throws a user warning. When you have changed your code to the new behaviour you should also change the compatibility mode to false so that no warning is thrown anymore. |