In Symfony we can translate strings/ text in controllers and twig.
//webkul.demo.text = 'Webkul Demo Text' //written in translation file $this->get('translator')->trans('webkul.demo.text'); //translate variable $webkulDemoText = 'webkul.demo.text'; $this->get('translator')->trans($webkulDemoText);
In twig we use this
{% trans %}webkul.demo.text{% trans %}
Previous twig syntax will not work for variables and will show error then how can we translate any variable in twig ? For this we have to use trans as a filter
{{ webkulDemoText|trans }}
Framework used – Symfony 2.7, Twig Official Doc & Symfony Official Doc
1 comments