Explorar o código

[ZF-7560] Zend_Translate:

- added numeric key support (note that using such notations is VERY unsave)

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@17760 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas %!s(int64=16) %!d(string=hai) anos
pai
achega
9a45a07331
Modificáronse 2 ficheiros con 14 adicións e 1 borrados
  1. 1 1
      library/Zend/Translate/Adapter.php
  2. 13 0
      tests/Zend/TranslateTest.php

+ 1 - 1
library/Zend/Translate/Adapter.php

@@ -479,7 +479,7 @@ abstract class Zend_Translate_Adapter {
                 $this->_translate[$key] = array();
             }
 
-            $this->_translate[$key] = array_merge($this->_translate[$key], $temp[$key]);
+            $this->_translate[$key] = $temp[$key] + $this->_translate[$key];
         }
 
         if ($this->_automatic === true) {

+ 13 - 0
tests/Zend/TranslateTest.php

@@ -562,6 +562,19 @@ class Zend_TranslateTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * ZF-7560
+     */
+    public function testUseNumericTranslations()
+    {
+        $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, array(0 => 'Message 1', 2 => 'Message 2'), 'en');
+        $this->assertEquals('Message 1', $lang->_(0));
+        $this->assertEquals('Message 2', $lang->_(2));
+
+        $lang->addTranslation(array(4 => 'Message 4'), 'en');
+        $this->assertEquals('Message 4', $lang->_(4));
+    }
+
+    /**
      * Ignores a raised PHP error when in effect, but throws a flag to indicate an error occurred
      *
      * @param  integer $errno