Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set translation domain for every twig

Tags:

php

twig

symfony

I have some twigs include the text which needs to be translated.

Currently I put this sentence in every twig.

{% trans_default_domain 'AcmeTopBundle' %}

However it is a little bit bothering.

Is there a good way to set default domain for every twigs in one place??

like image 269
whitebear Avatar asked Nov 10 '22 09:11

whitebear


1 Answers

You can write a custom node visitor based on the original Symfony\Bridge\Twig\NodeVisitor\TranslationDefaultDomainNodeVisitor:

https://gist.github.com/connorhu/3254272188d81d1f9d7322dbdebeb0e0

like image 106
connorhu Avatar answered Nov 14 '22 23:11

connorhu