Created
October 19, 2011 17:31
-
-
Save MasonM/1299031 to your computer and use it in GitHub Desktop.
Change Zend_View_Helper_Translate->translate() to not treat last parameter as a locale if it would result in errors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Index: tests/Zend/View/Helper/TranslateTest.php | |
=================================================================== | |
--- tests/Zend/View/Helper/TranslateTest.php (revision 24514) | |
+++ tests/Zend/View/Helper/TranslateTest.php (working copy) | |
@@ -206,6 +206,7 @@ | |
$this->helper->setTranslator($trans); | |
$this->assertEquals("drei 100 200", $this->helper->translate("three %1\$s %2\$s", "100", "200")); | |
$this->assertEquals("tre 100 200", $this->helper->translate("three %1\$s %2\$s", "100", "200", 'it')); | |
+ $this->assertEquals("drei 100 it", $this->helper->translate("three %1\$s %2\$s", "100", "it")); | |
$this->assertEquals("drei 100 200", $this->helper->translate("three %1\$s %2\$s", array("100", "200"))); | |
$this->assertEquals("tre 100 200", $this->helper->translate("three %1\$s %2\$s", array("100", "200"), 'it')); | |
} | |
Index: library/Zend/View/Helper/Translate.php | |
=================================================================== | |
--- library/Zend/View/Helper/Translate.php (revision 24514) | |
+++ library/Zend/View/Helper/Translate.php (working copy) | |
@@ -79,7 +79,10 @@ | |
$locale = null; | |
if ($count > 0) { | |
if (Zend_Locale::isLocale($options[($count - 1)], null, false) !== false) { | |
- $locale = array_pop($options); | |
+ // Don't treat last option as the locale if doing so will result in an error | |
+ if (is_array($options[0]) || @vsprintf($messageid, array_slice($options, 0, -1)) !== false) { | |
+ $locale = array_pop($options); | |
+ } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment