Ver Fonte

[ZF-8448] Zend_Translate:

- fixed routing of non-translated input to give no notices

git-svn-id: http://framework.zend.com/svn/framework/standard/trunk@19367 44c647ce-9c0f-0410-b52a-842ac1e357ba
thomas há 16 anos atrás
pai
commit
8a4bbc145c
2 ficheiros alterados com 13 adições e 2 exclusões
  1. 2 2
      library/Zend/Translate/Adapter.php
  2. 11 0
      tests/Zend/TranslateTest.php

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

@@ -577,7 +577,7 @@ abstract class Zend_Translate_Adapter {
         }
 
         $locale = (string) $locale;
-        if (isset($this->_translate[$locale][$messageId])) {
+        if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
             // return original translation
             if ($plural === null) {
                 return $this->_translate[$locale][$messageId];
@@ -591,7 +591,7 @@ abstract class Zend_Translate_Adapter {
             // faster than creating a new locale and separate the leading part
             $locale = substr($locale, 0, -strlen(strrchr($locale, '_')));
 
-            if (isset($this->_translate[$locale][$messageId])) {
+            if ((is_string($messageId) || is_int($messageId)) && isset($this->_translate[$locale][$messageId])) {
                 // return regionless translation (en_US -> en)
                 if ($plural === null) {
                     return $this->_translate[$locale][$messageId];

+ 11 - 0
tests/Zend/TranslateTest.php

@@ -626,6 +626,17 @@ class Zend_TranslateTest extends PHPUnit_Framework_TestCase
     }
 
     /**
+     * Translating Object
+     */
+    public function testObjectTranslation()
+    {
+        $lang = new Zend_Translate(Zend_Translate::AN_ARRAY, dirname(__FILE__) . '/Translate/Adapter/_files/testarray', 'en_GB', array('scan' => Zend_Translate::LOCALE_DIRECTORY));
+        $this->assertEquals('Message 1 (ja)', $lang->_('Message 1', 'ja'));
+
+        $this->assertEquals($lang, $lang->translate($lang));
+    }
+
+    /**
      * Ignores a raised PHP error when in effect, but throws a flag to indicate an error occurred
      *
      * @param  integer $errno