Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/Symfony/Bridge/Twig/Extension/TranslationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class TranslationExtension extends AbstractExtension
private $translator;
private $translationNodeVisitor;

public function __construct(TranslatorInterface $translator, NodeVisitorInterface $translationNodeVisitor = null)
public function __construct(TranslatorInterface $translator = null, NodeVisitorInterface $translationNodeVisitor = null)
{
if (!$translationNodeVisitor) {
$translationNodeVisitor = new TranslationNodeVisitor();
Expand Down Expand Up @@ -94,11 +94,19 @@ public function getTranslationNodeVisitor()

public function trans($message, array $arguments = array(), $domain = null, $locale = null)
{
if (null === $this->translator) {
return $message;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should still replace arguments IMO. Otherwise this does not work even for the case where the English message is the source

}

return $this->translator->trans($message, $arguments, $domain, $locale);
}

public function transchoice($message, $count, array $arguments = array(), $domain = null, $locale = null)
{
if (null === $this->translator) {
return $message;
}

return $this->translator->transChoice($message, $count, array_merge(array('%count%' => $count), $arguments), $domain, $locale);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@ public function process(ContainerBuilder $container)
if (!interface_exists('Symfony\Component\Routing\Generator\UrlGeneratorInterface')) {
$container->removeDefinition('twig.extension.routing');
}
if (!interface_exists('Symfony\Component\Translation\TranslatorInterface')) {
$container->removeDefinition('twig.extension.trans');
}

if (!class_exists('Symfony\Component\Yaml\Yaml')) {
$container->removeDefinition('twig.extension.yaml');
Expand All @@ -49,10 +46,6 @@ public function process(ContainerBuilder $container)
$container->getDefinition('twig.loader.native_filesystem')->addMethodCall('addPath', array(dirname(dirname($reflClass->getFileName())).'/Resources/views/Form'));
}

if ($container->has('translator')) {
$container->getDefinition('twig.extension.trans')->addTag('twig.extension');
}

if ($container->has('router')) {
$container->getDefinition('twig.extension.routing')->addTag('twig.extension');
}
Expand Down
3 changes: 2 additions & 1 deletion src/Symfony/Bundle/TwigBundle/Resources/config/twig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
</service>

<service id="twig.extension.trans" class="Symfony\Bridge\Twig\Extension\TranslationExtension">
<argument type="service" id="translator" />
<argument type="service" id="translator" on-invalid="null" />
<tag name="twig.extension" />
</service>

<service id="twig.extension.assets" class="Symfony\Bridge\Twig\Extension\AssetExtension">
Expand Down