Ver Fonte

[ZF-6696] Zend_Locale:

- added new postal code data
- erased datepattern (no longer supported by CLDR)
- depreciated several duplicated methods

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15666 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas há 16 anos atrás
pai
commit
91fa13061a

+ 19 - 19
documentation/manual/en/module_specs/Zend_Locale-Functions.xml

@@ -230,14 +230,12 @@ print Zend_Locale::getTranslation('de', 'language', 'zh');
                     <row>
                         <entry><emphasis>Language</emphasis></entry>
                         <entry>Returns a localized list of all languages. The language part of the locale
-                            is returned as key and the translation as value. For your convenience use the
-                            <code>getLanguageTranslationList()</code> method</entry>
+                            is returned as key and the translation as value</entry>
                     </row>
                     <row>
                         <entry><emphasis>Script</emphasis></entry>
                         <entry>Returns a localized list of all scripts. The script is returned as key and the
-                            translation as value. For your convenience use the
-                            <code>getScriptTranslationList()</code> method</entry>
+                            translation as value</entry>
                     </row>
                     <row>
                         <entry><emphasis>Territory</emphasis></entry>
@@ -246,10 +244,7 @@ print Zend_Locale::getTranslation('de', 'language', 'zh');
                             use '1' as value. To get only countries use '2' as value. The country part of
                             the locale is used as key where applicable. In the other case the official ISO
                             code for this territory is used. The translated territory is returned as value.
-                            For your convenience use the <code>getCountryTranslationList()</code> method
-                            to receive all countries and the <code>getTerritoryTranslationList()</code>
-                            method to receive all territories without countries. When you omit the value
-                            you will get a list with both.</entry>
+                            When you omit the value you will get a list with both.</entry>
                     </row>
                     <row>
                         <entry><emphasis>Variant</emphasis></entry>
@@ -568,6 +563,12 @@ print Zend_Locale::getTranslation('de', 'language', 'zh');
                             character code is used as array key and the territory (region) as array value
                         </entry>
                     </row>
+                    <row>
+                        <entry><emphasis>PostalToTerritory</emphasis></entry>
+                        <entry>Returns a list of territories with a regex for postal codes which are
+                            included within that territory. The ISO territory code ('territory') is used as
+                            array key and the regex as array value.</entry>
+                    </row>
                 </tbody>
             </tgroup>
         </table>
@@ -603,22 +604,19 @@ print Zend_Locale::getTranslation('de', 'language', 'zh');
                     <row>
                         <entry><emphasis>Language</emphasis></entry>
                         <entry>Returns a translation for a language. To select the wished translation
-                            you must give the language code as value. For your convenience use the
-                            <code>getLanguageTranslation($value)</code> method</entry>
+                            you must give the language code as value</entry>
                     </row>
                     <row>
                         <entry><emphasis>Script</emphasis></entry>
                         <entry>Returns a translation for a script. To select the wished translation you
-                            must give the script code as value. For your convenience use the
-                            <code>getScriptTranslation($value)</code> method</entry>
+                            must give the script code as value</entry>
                     </row>
                     <row>
                         <entry><emphasis>Territory</emphasis> or
                             <emphasis>Country</emphasis></entry>
                         <entry>Returns a translation for a territory. This can be countries, continents
                             and territories. To select the wished variant you must give the territory
-                            code as value. For your convenience use the
-                            <code>getCountryTranslation($value)</code> method.</entry>
+                            code as value</entry>
                     </row>
                     <row>
                         <entry><emphasis>Variant</emphasis></entry>
@@ -632,11 +630,6 @@ print Zend_Locale::getTranslation('de', 'language', 'zh');
                             select the wished key you must give the key code as value</entry>
                     </row>
                     <row>
-                        <entry><emphasis>DateChars</emphasis></entry>
-                        <entry>Returns a character table which contains all characters used when displaying
-                            dates</entry>
-                    </row>
-                    <row>
                         <entry><emphasis>DefaultCalendar</emphasis></entry>
                         <entry>Returns the default calendar for the given locale. For most locales this
                             will be 'gregorian'. Use
@@ -946,6 +939,13 @@ print Zend_Locale::getTranslation('de', 'language', 'zh');
                         <entry><emphasis>TerritoryToAlpha3</emphasis></entry>
                         <entry>Returns the territory (region) for a 3 sign character code</entry>
                     </row>
+                    <row>
+                        <entry><emphasis>PostalToTerritory</emphasis></entry>
+                        <entry>
+                            Returns the a regex for postal codes for a given territory. The
+                            territory has to be given as ISO4217 string for example '001' for
+                            world</entry>
+                    </row>
                 </tbody>
             </tgroup>
         </table>

+ 63 - 0
documentation/manual/en/module_specs/Zend_Locale-Migration.xml

@@ -11,6 +11,69 @@
         use the new API.
     </para>
 
+    <sect2 id="zend.locale.migration.fromoneeighttoonenine">
+        <title>Migrating from 1.8 to 1.9 or newer</title>
+        <sect3 id="zend.locale.migration.fromoneeighttoonenine.depreciated">
+            <title>Depreciated methods</title>
+
+            <para>
+                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.
+            </para>
+
+            <table id="zend.locale.migration.fromoneeighttoonenine.depreciated.table-1">
+
+                <title>List of measurement types</title>
+
+                <tgroup cols="2">
+                    <thead>
+                        <row>
+                            <entry>Old call</entry>
+                            <entry>New call</entry>
+                        </row>
+                    </thead>
+                    <tbody>
+                        <row>
+                            <entry>getLanguageTranslationList($locale)</entry>
+                            <entry>getTranslationList('language', $locale)</entry>
+                        </row>
+                        <row>
+                            <entry>getScriptTranslationList($locale)</entry>
+                            <entry>getTranslationList('script', $locale)</entry>
+                        </row>
+                        <row>
+                            <entry>getCountryTranslationList($locale)</entry>
+                            <entry>getTranslationList('territory', $locale, 2)</entry>
+                        </row>
+                        <row>
+                            <entry>getTerritoryTranslationList($locale)</entry>
+                            <entry>getTranslationList('territory', $locale, 1)</entry>
+                        </row>
+                        <row>
+                            <entry>getLanguageTranslation($value, $locale)</entry>
+                            <entry>getTranslation($value, 'language', $locale)</entry>
+                        </row>
+                        <row>
+                            <entry>getScriptTranslation($value, $locale)</entry>
+                            <entry>getTranslation($value, 'script', $locale)</entry>
+                        </row>
+                        <row>
+                            <entry>getCountryTranslation($value, $locale)</entry>
+                            <entry>getTranslation($value, 'country', $locale)</entry>
+                        </row>
+                        <row>
+                            <entry>getTerritoryTranslation($value, $locale)</entry>
+                            <entry>getTranslation($value, 'territory', $locale)</entry>
+                        </row>
+                    </tbody>
+                </tgroup>
+            </table>
+
+        </sect3>
+    </sect2>
+
     <sect2 id="zend.locale.migration.fromonesixtooneseven">
         <title>Migrating from 1.6 to 1.7 or newer</title>
         <sect3 id="zend.locale.migration.fromonesixtooneseven.islocale">

+ 16 - 0
library/Zend/Locale.php

@@ -538,9 +538,11 @@ class Zend_Locale
      *
      * @param  string|Zend_Locale $locale (Optional) Locale for language translation
      * @return array
+     * @deprecated
      */
     public static function getLanguageTranslationList($locale = null)
     {
+        trigger_error("The method getLanguageTranslationList is deprecated. Use getTranslationList('language', $locale) instead", E_USER_NOTICE);
         return self::getTranslationList('language', $locale);
     }
 
@@ -549,9 +551,11 @@ class Zend_Locale
      *
      * @param  string|Zend_Locale $locale (Optional) Locale for script translation
      * @return array
+     * @deprecated
      */
     public static function getScriptTranslationList($locale = null)
     {
+        trigger_error("The method getScriptTranslationList is deprecated. Use getTranslationList('script', $locale) instead", E_USER_NOTICE);
         return self::getTranslationList('script', $locale);
     }
 
@@ -560,9 +564,11 @@ class Zend_Locale
      *
      * @param  string|Zend_Locale $locale (Optional) Locale for country translation
      * @return array
+     * @deprecated
      */
     public static function getCountryTranslationList($locale = null)
     {
+        trigger_error("The method getCountryTranslationList is deprecated. Use getTranslationList('territory', $locale, 2) instead", E_USER_NOTICE);
         return self::getTranslationList('territory', $locale, 2);
     }
 
@@ -572,9 +578,11 @@ class Zend_Locale
      *
      * @param  string|Zend_Locale $locale (Optional) Locale for territory translation
      * @return array
+     * @deprecated
      */
     public static function getTerritoryTranslationList($locale = null)
     {
+        trigger_error("The method getTerritoryTranslationList is deprecated. Use getTranslationList('territory', $locale, 1) instead", E_USER_NOTICE);
         return self::getTranslationList('territory', $locale, 1);
     }
 
@@ -605,9 +613,11 @@ class Zend_Locale
      * @param  string $value  Name to get detailed information about
      * @param  string $locale (Optional) Locale for language translation
      * @return array
+     * @deprecated
      */
     public static function getLanguageTranslation($value, $locale = null)
     {
+        trigger_error("The method getLanguageTranslation is deprecated. Use getTranslation($value, 'language', $locale) instead", E_USER_NOTICE);
         return self::getTranslation($value, 'language', $locale);
     }
 
@@ -617,9 +627,11 @@ class Zend_Locale
      * @param  string $value  Name to get detailed information about
      * @param  string $locale (Optional) locale for script translation
      * @return array
+     * @deprecated
      */
     public static function getScriptTranslation($value, $locale = null)
     {
+        trigger_error("The method getScriptTranslation is deprecated. Use getTranslation($value, 'script', $locale) instead", E_USER_NOTICE);
         return self::getTranslation($value, 'script', $locale);
     }
 
@@ -629,9 +641,11 @@ class Zend_Locale
      * @param  string             $value  Name to get detailed information about
      * @param  string|Zend_Locale $locale (Optional) Locale for country translation
      * @return array
+     * @deprecated
      */
     public static function getCountryTranslation($value, $locale = null)
     {
+        trigger_error("The method getCountryTranslation is deprecated. Use getTranslation($value, 'country', $locale) instead", E_USER_NOTICE);
         return self::getTranslation($value, 'country', $locale);
     }
 
@@ -642,9 +656,11 @@ class Zend_Locale
      * @param  string             $value  Name to get detailed information about
      * @param  string|Zend_Locale $locale (Optional) Locale for territory translation
      * @return array
+     * @deprecated
      */
     public static function getTerritoryTranslation($value, $locale = null)
     {
+        trigger_error("The method getTerritoryTranslation is deprecated. Use getTranslation($value, 'territory', $locale) instead", E_USER_NOTICE);
         return self::getTranslation($value, 'territory', $locale);
     }
 

+ 11 - 4
library/Zend/Locale/Data.php

@@ -800,6 +800,13 @@ class Zend_Locale_Data
                 }
                 break;
 
+            case 'postaltoterritory':
+                $_temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex', 'territoryId');
+                foreach ($_temp as $key => $keyvalue) {
+                    $temp += self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $key . '\']', 'territoryId');
+                }
+                break;
+
             default :
                 require_once 'Zend/Locale/Exception.php';
                 throw new Zend_Locale_Exception("Unknown list ($path) for parsing locale data.");
@@ -867,10 +874,6 @@ class Zend_Locale_Data
                 $temp = self::_getFile($locale, '/ldml/localeDisplayNames/keys/key[@type=\'' . $value . '\']', 'type');
                 break;
 
-            case 'datechars':
-                $temp = self::_getFile($locale, '/ldml/dates/localizedPatternChars', '', 'chars');
-                break;
-
             case 'defaultcalendar':
                 $temp = self::_getFile($locale, '/ldml/dates/calendars/default', 'choice', 'default');
                 break;
@@ -1241,6 +1244,10 @@ class Zend_Locale_Data
                 $temp = self::_getFile('supplementalData', '/supplementalData/codeMappings/territoryCodes[@alpha3=\''.$value.'\']', 'type', $value);
                 break;
 
+            case 'postaltoterritory':
+                $temp = self::_getFile('postalCodeData', '/supplementalData/postalCodeData/postCodeRegex[@territoryId=\'' . $value . '\']', 'territoryId');
+                break;
+
             default :
                 require_once 'Zend/Locale/Exception.php';
                 throw new Zend_Locale_Exception("Unknown detail ($path) for parsing locale data.");

+ 174 - 2
tests/Zend/Locale/DataTest.php

@@ -2101,7 +2101,7 @@ class Zend_Locale_DataTest extends PHPUnit_Framework_TestCase
     }
 
     /**
-     * test for reading phonetoterritory from locale
+     * test for reading numerictoterritory from locale
      * expected array
      */
     public function testNumericToTerritory()
@@ -2227,7 +2227,7 @@ class Zend_Locale_DataTest extends PHPUnit_Framework_TestCase
     }
 
     /**
-     * test for reading phonetoterritory from locale
+     * test for reading alpha3toterritory from locale
      * expected array
      */
     public function testAlpha3ToTerritory()
@@ -2288,4 +2288,176 @@ class Zend_Locale_DataTest extends PHPUnit_Framework_TestCase
         $value = Zend_Locale_Data::getContent('de_AT', 'alpha3toterritory', 'AT');
         $this->assertEquals("AUT", $value);
     }
+
+    /**
+     * test for reading postaltoterritory from locale
+     * expected array
+     */
+    public function testPostalToTerritory()
+    {
+        $value = Zend_Locale_Data::getList('de_AT', 'postaltoterritory');
+        $result = array('GB' => 'GIR[ ]?0AA|((AB|AL|B|BA|BB|BD|BH|BL|BN|BR|BS|BT|CA|CB|CF|CH|CM|CO|CR|CT|CV|CW|DA|DD|DE|DG|DH|DL|DN|DT|DY|E|EC|EH|EN|EX|FK|FY|G|GL|GY|GU|HA|HD|HG|HP|HR|HS|HU|HX|IG|IM|IP|IV|JE|KA|KT|KW|KY|L|LA|LD|LE|LL|LN|LS|LU|M|ME|MK|ML|N|NE|NG|NN|NP|NR|NW|OL|OX|PA|PE|PH|PL|PO|PR|RG|RH|RM|S|SA|SE|SG|SK|SL|SM|SN|SO|SP|SR|SS|ST|SW|SY|TA|TD|TF|TN|TQ|TR|TS|TW|UB|W|WA|WC|WD|WF|WN|WR|WS|WV|YO|ZE)(\d[\dA-Z]?[]?\d[ABD-HJLN-UW-Z]{2}))|BFPO[ ]?\d{1,4}',
+            'JE' => 'JE\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}',
+            'GG' => 'GY\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}',
+            'IM' => 'IM\d[\dA-Z]?[ ]?\d[ABD-HJLN-UW-Z]{2}',
+            'US' => '\d{5}([ \-]\d{4})?',
+            'CA' => '[ABCEGHJKLMNPRSTVXY]\d[A-Z][ ]?\d[A-Z]\d',
+            'DE' => '\d{5}',
+            'JP' => '\d{3}-\d{4}',
+            'FR' => '\d{2}[ ]?\d{3}',
+            'AU' => '\d{4}',
+            'IT' => '\d{5}',
+            'CH' => '\d{4}',
+            'AT' => '\d{4}',
+            'ES' => '\d{5}',
+            'NL' => '\d{4}[ ]?[A-Z]{2}',
+            'BE' => '\d{4}',
+            'DK' => '\d{4}',
+            'SE' => '\d{3}[ ]?\d{2}',
+            'NO' => '\d{4}',
+            'BR' => '\d{5}[\-]?\d{3}',
+            'PT' => '\d{4}([\-]\d{3})?',
+            'FI' => '\d{5}',
+            'AX' => '22\d{3}',
+            'KR' => '\d{3}[\-]\d{3}',
+            'CN' => '\d{6}',
+            'TW' => '\d{3}(\d{2})?',
+            'SG' => '\d{6}',
+            'DZ' => '\d{5}',
+            'AD' => 'AD\d{3}',
+            'AR' => '([A-HJ-NP-Z])?\d{4}([A-Z]{3})?',
+            'AM' => '(37)?\d{4}',
+            'AZ' => '\d{4}',
+            'BH' => '((1[0-2]|[2-9])\d{2})?',
+            'BD' => '\d{4}',
+            'BB' => '(BB\d{5})?',
+            'BY' => '\d{6}',
+            'BM' => '[A-Z]{2}[ ]?[A-Z0-9]{2}',
+            'BA' => '\d{5}',
+            'IO' => 'BBND 1ZZ',
+            'BN' => '[A-Z]{2}[ ]?\d{4}',
+            'BG' => '\d{4}',
+            'KH' => '\d{5}',
+            'CV' => '\d{4}',
+            'CL' => '\d{7}',
+            'CR' => '\d{4,5}|\d{3}-\d{4}',
+            'HR' => '\d{5}',
+            'CY' => '\d{4}',
+            'CZ' => '\d{3}[ ]?\d{2}',
+            'DO' => '\d{5}',
+            'EC' => '([A-Z]\d{4}[A-Z]|(?:[A-Z]{2})?\d{6})?',
+            'EG' => '\d{5}',
+            'EE' => '\d{5}',
+            'FO' => '\d{3}',
+            'GE' => '\d{4}',
+            'GR' => '\d{3}[ ]?\d{2}',
+            'GL' => '39\d{2}',
+            'GT' => '\d{5}',
+            'HT' => '\d{4}',
+            'HN' => '(?:\d{5})?',
+            'HU' => '\d{4}',
+            'IS' => '\d{3}',
+            'IN' => '\d{6}',
+            'ID' => '\d{5}',
+            'IE' => '((D|DUBLIN)?([1-9]|6[wW]|1[0-8]|2[024]))?',
+            'IL' => '\d{5}',
+            'JO' => '\d{5}',
+            'KZ' => '\d{6}',
+            'KE' => '\d{5}',
+            'KW' => '\d{5}',
+            'LA' => '\d{5}',
+            'LV' => '\d{4}',
+            'LB' => '(\d{4}([ ]?\d{4})?)?',
+            'LI' => '(948[5-9])|(949[0-7])',
+            'LT' => '\d{5}',
+            'LU' => '\d{4}',
+            'MK' => '\d{4}',
+            'MY' => '\d{5}',
+            'MV' => '\d{5}',
+            'MT' => '[A-Z]{3}[ ]?\d{2,4}',
+            'MU' => '(\d{3}[A-Z]{2}\d{3})?',
+            'MX' => '\d{5}',
+            'MD' => '\d{4}',
+            'MC' => '980\d{2}',
+            'MA' => '\d{5}',
+            'NP' => '\d{5}',
+            'NZ' => '\d{4}',
+            'NI' => '((\d{4}-)?\d{3}-\d{3}(-\d{1})?)?',
+            'NG' => '(\d{6})?',
+            'OM' => '(PC )?\d{3}',
+            'PK' => '\d{5}',
+            'PY' => '\d{4}',
+            'PH' => '\d{4}',
+            'PL' => '\d{2}-\d{3}',
+            'PR' => '00[679]\d{2}([ \-]\d{4})?',
+            'RO' => '\d{6}',
+            'RU' => '\d{6}',
+            'SM' => '4789\d',
+            'SA' => '\d{5}',
+            'SN' => '\d{5}',
+            'SK' => '\d{3}[ ]?\d{2}',
+            'SI' => '\d{4}',
+            'ZA' => '\d{4}',
+            'LK' => '\d{5}',
+            'TJ' => '\d{6}',
+            'TH' => '\d{5}',
+            'TN' => '\d{4}',
+            'TR' => '\d{5}',
+            'TM' => '\d{6}',
+            'UA' => '\d{5}',
+            'UY' => '\d{5}',
+            'UZ' => '\d{6}',
+            'VA' => '00120',
+            'VE' => '\d{4}',
+            'ZM' => '\d{5}',
+            'AS' => '96799',
+            'CC' => '6799',
+            'CK' => '\d{4}',
+            'RS' => '\d{6}',
+            'ME' => '8\d{4}',
+            'CS' => '\d{5}',
+            'YU' => '\d{5}',
+            'CX' => '6798',
+            'ET' => '\d{4}',
+            'FK' => 'FIQQ 1ZZ',
+            'NF' => '2899',
+            'FM' => '(9694[1-4])([ \-]\d{4})?',
+            'GF' => '9[78]3\d{2}',
+            'GN' => '\d{3}',
+            'GP' => '9[78][01]\d{2}',
+            'GS' => 'SIQQ 1ZZ',
+            'GU' => '969[123]\d([ \-]\d{4})?',
+            'GW' => '\d{4}',
+            'HM' => '\d{4}',
+            'IQ' => '\d{5}',
+            'KG' => '\d{6}',
+            'LR' => '\d{4}',
+            'LS' => '\d{3}',
+            'MG' => '\d{3}',
+            'MH' => '969[67]\d([ \-]\d{4})?',
+            'MN' => '\d{6}',
+            'MP' => '9695[012]([ \-]\d{4})?',
+            'MQ' => '9[78]2\d{2}',
+            'NC' => '988\d{2}',
+            'NE' => '\d{4}',
+            'VI' => '008(([0-4]\d)|(5[01]))([ \-]\d{4})?',
+            'PF' => '987\d{2}',
+            'PG' => '\d{3}',
+            'PM' => '9[78]5\d{2}',
+            'PN' => 'PCRN 1ZZ',
+            'PW' => '96940',
+            'RE' => '9[78]4\d{2}',
+            'SH' => 'STHL 1ZZ',
+            'SJ' => '\d{4}',
+            'SO' => '\d{5}',
+            'SZ' => '[HLMS]\d{3}',
+            'TC' => 'TKCA 1ZZ',
+            'WF' => '986\d{2}',
+            'YT' => '976\d{2}'
+        );
+        $this->assertEquals($result, $value);
+
+        $value = Zend_Locale_Data::getContent('de_AT', 'postaltoterritory', 'AT');
+        $this->assertEquals("\d{4}", $value);
+    }
 }