Navigation Menu

Skip to content

Commit

Permalink
[TwigBridge] Made the locale configurable for the trans and transchoi…
Browse files Browse the repository at this point in the history
…ce filters
  • Loading branch information
stof committed Jul 25, 2011
1 parent 1543ad1 commit 3ea31a0
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/Symfony/Bridge/Twig/Extension/TranslationExtension.php
Expand Up @@ -63,14 +63,14 @@ public function getTokenParsers()
);
}

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);
}

/**
Expand Down
Expand Up @@ -78,10 +78,12 @@ public function getTransTests()
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)),
);
}

Expand Down

0 comments on commit 3ea31a0

Please sign in to comment.