Просмотр исходного кода

[ZF-6702] Zend_Locale:

 - added support for calendar units

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@15958 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas 16 лет назад
Родитель
Сommit
314d21d7ea

+ 15 - 0
documentation/manual/en/module_specs/Zend_Locale-Functions.xml

@@ -610,6 +610,13 @@ print Zend_Locale::getTranslation('de', 'language', 'zh');
                             language to a full qualified locale
                         </entry>
                     </row>
+                    <row>
+                        <entry><emphasis>Unit</emphasis></entry>
+                        <entry>
+                            Returns a list of localized calendar units. This can be used to translate
+                            the strings "day", "month" and so on automatically
+                        </entry>
+                    </row>
                 </tbody>
             </tgroup>
         </table>
@@ -1029,6 +1036,14 @@ print Zend_Locale::getTranslation('de', 'language', 'zh');
                             upgrade this language to a full qualified locale
                         </entry>
                     </row>
+                    <row>
+                        <entry><emphasis>Unit</emphasis></entry>
+                        <entry>
+                            Returns a localized calendar unit. This can be used to translate
+                            the strings "day", "month" and so on automatically. The first parameter
+                            has to be the type, and the second parameter has to be the count
+                        </entry>
+                    </row>
                 </tbody>
             </tgroup>
         </table>

+ 12 - 0
library/Zend/Locale/Data.php

@@ -870,6 +870,14 @@ class Zend_Locale_Data
                 }
                 break;
 
+            case 'unit':
+                $_temp = self::_getFile($locale, '/ldml/units/unit', 'type');
+                foreach($_temp as $key => $keyvalue) {
+                    $_temp2 = self::_getFile($locale, '/ldml/units/unit[@type=\'' . $key . '\']/unitPattern', 'count');
+                    $temp[$key] = $_temp2;
+                }
+                break;
+
             default :
                 require_once 'Zend/Locale/Exception.php';
                 throw new Zend_Locale_Exception("Unknown list ($path) for parsing locale data.");
@@ -1362,6 +1370,10 @@ class Zend_Locale_Data
                 $temp = self::_getFile('likelySubtags', '/supplementalData/likelySubtags/likelySubtag[@from=\'' . $value . '\']', 'to', $value);
                 break;
 
+            case 'unit':
+                $temp = self::_getFile($locale, '/ldml/units/unit[@type=\'' . $value[0] . '\']/unitPattern[@count=\'' . $value[1] . '\']', '');
+                break;
+
             default :
                 require_once 'Zend/Locale/Exception.php';
                 throw new Zend_Locale_Exception("Unknown detail ($path) for parsing locale data.");

+ 22 - 0
tests/Zend/Locale/DataTest.php

@@ -2702,4 +2702,26 @@ class Zend_Locale_DataTest extends PHPUnit_Framework_TestCase
         $value = Zend_Locale_Data::getContent('de_AT', 'dateinterval', array('gregorian', 'yMMMM', 'y'));
         $this->assertEquals("MM.yyyy – MM.yyyy", $value);
     }
+
+    /**
+     * test for reading intervalformat from locale
+     * expected array
+     */
+    public function testUnit()
+    {
+        $value = Zend_Locale_Data::getList('de_AT', 'unit');
+        $result = array(
+            'day' => array('one' => '{0} Tag', 'other' => '{0} Tage'),
+            'hour' => array('one' => '{0} Stunde', 'other' => '{0} Stunden'),
+            'minute' => array('one' => '{0} Minute', 'other' => '{0} Minuten'),
+            'month' => array('one' => '{0} Monat', 'other' => '{0} Monate'),
+            'second' => array('one' => '{0} Sekunde', 'other' => '{0} Sekunden'),
+            'week' => array('one' => '{0} Woche', 'other' => '{0} Wochen'),
+            'year' => array('one' => '{0} Jahr', 'other' => '{0} Jahre')
+        );
+        $this->assertEquals($result, $value);
+
+        $value = Zend_Locale_Data::getContent('de_AT', 'unit', array('day', 'one'));
+        $this->assertEquals('{0} Tag', $value);
+    }
 }