Can I put a twig variable inside a translated string?

I’ve sucessfully created a languages.yaml file with text strings which is working great but I’m wondering if its possible to take a step further and insert twig variables into a string. For example I have string like “Follow XX on Twitter” where I would like to do something like “Follow {{ page.header.post_author }} on Twitter”. Is there anyway other than string concatenation to do this?

Hi @Ptarmic -

This is the way to insert variables into your language string:

Translations with Variables

In your language file:

FOLLOW: Follow %s on %s.

then in your template:

{{ 'FOLLOW'|t( page.header.post_author,  'Twitter' )  }}
  • phi
1 Like

Thanks @phi that worked perfectly!