Ver Fonte

[TwigBridge] Made the locale configurable for the trans and transchoice filters

Christophe Coevoet há 14 anos atrás
pai
commit
3ea31a0263

+ 4 - 4
src/Symfony/Bridge/Twig/Extension/TranslationExtension.php

@@ -63,14 +63,14 @@ class TranslationExtension extends \Twig_Extension
         );
     }
 
-    public function trans($message, array $arguments = array(), $domain = "messages")
+    public function trans($message, array $arguments = array(), $domain = "messages", $locale = null)
     {
-        return $this->translator->trans($message, $arguments, $domain);
+        return $this->translator->trans($message, $arguments, $domain, $locale);
     }
 
-    public function transchoice($message, $count, array $arguments = array(), $domain = "messages")
+    public function transchoice($message, $count, array $arguments = array(), $domain = "messages", $locale = null)
     {
-        return $this->translator->transChoice($message, $count, array_merge(array('%count%' => $count), $arguments), $domain);
+        return $this->translator->transChoice($message, $count, array_merge(array('%count%' => $count), $arguments), $domain, $locale);
     }
 
     /**

+ 2 - 0
tests/Symfony/Tests/Bridge/Twig/Extension/TranslationExtensionTest.php

@@ -78,10 +78,12 @@ class TranslationExtensionTest extends TestCase
             array('{{ name|trans }}', 'Symfony2', array('name' => 'Symfony2')),
             array('{{ hello|trans({ \'%name%\': \'Symfony2\' }) }}', 'Hello Symfony2', array('hello' => 'Hello %name%')),
             array('{% set vars = { \'%name%\': \'Symfony2\' } %}{{ hello|trans(vars) }}', 'Hello Symfony2', array('hello' => 'Hello %name%')),
+            array('{{ "Hello"|trans({}, "messages", "fr") }}', 'Hello'),
 
             // transchoice filter
             array('{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|transchoice(count) }}', 'There is 5 apples', array('count' => 5)),
             array('{{ text|transchoice(5, {\'%name%\': \'Symfony2\'}) }}', 'There is 5 apples (Symfony2)', array('text' => '{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples (%name%)')),
+            array('{{ "{0} There is no apples|{1} There is one apple|]1,Inf] There is %count% apples"|transchoice(count, {}, "messages", "fr") }}', 'There is 5 apples', array('count' => 5)),
         );
     }