1

I was just going through one of the Twig files in the Bolt default theme template, and I came across the following line of code:

{{ __("Unfortunately, no content could be found. Try another page, or go to the <a href=\"%paths_root%\">homepage</a>.", {'%paths_root%': paths.root} ) }}

Now I thought the way you echo something in Twig is as follows:

{{ 'hello there' }}

I googled double underline and found this, but I’m not sure that's the answer to my question.

So what exactly is the double underline in Twig or Bolt?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Alexander Solonik
  • 9,838
  • 18
  • 76
  • 174

2 Answers2

3

In the current stable Bolt version, __() is a Twig function to call our translation layer that sits on top of Symfony's.

The second parameter in that function is the value in the string that is variable, and the value you want inserted in its place for that specific translation string, at that point.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Gawain
  • 1,568
  • 10
  • 8
0

I’m not sure if I understand this correctly, but in the Symfony framework for translations of strings you should use the translator service.

Then you could use the trans and transchoice Twig tags.

Please see Symfony documentation for more details: Symfony translations

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Claude
  • 11
  • 5