How do I translate strings in Twig templates?


Use the t filter:

{{ 'translate me'|t }}

You need to visit the page in a language that is not English to have them picked up. That should be enough.

You can use the {% trans %} Twig tag, available in Drupal 8:

{% trans %}
  Submitted by {{ author.username }} on {{ node.created }}
{% endtrans %}

See the following link for more details:

Similar questions

Translate page.tpl.php strings
I have a custom slideshow and the phrases are all in page.tpl.php (please see figure attached) But they are not dynamic, so they are in PT. Now I have a multilingual site (I installed all the necessary modules) and everything in my site is working great. My question is: How can I translate those strings in page.tpl.php to English everytime I switch...
Translate strings in custom module
I'm working on a module for a D7 site that generates a block. Unfortunately all the HTML is hard coded and I need to make it translatable. I have done the following: Changed to but no amount of clearing caches or refreshing strings gets "Page title here" to appear in the translate interface. I've loaded the page and even changed the text but it doe...
t() function doesn't translate strings inside node fields
I built a rule using rules module to create a node of a certain content type which inserts a text of full_html format inside a body field when follow flag is flagged. This is the rule When a user uses Follow flag to follow another user, a message is sent to the followed user which says, !link started following you. This rule works perfectly but the...
How to translate strings available in JS library?
I'm showing some images on my site where those are displayed using jquery.magnific-popup.min.js library. I'm not able to translate a string in that library. i.e. "%curr% of %total%" It is not searchable even in the translate interface. How can I translate it?
Translate untranslated strings
I downloaded and enabled translations for my Drupal core and modules using these Drush commands: I got almost everything translated, and in "Administration » Configuration » Regional and language" I see that I have almost 60% of translations to Lithuanian. However, not everything is translated. For example, harmony forum module thread reply; and us...
Translate not working for some strings
I am using Drupal commons. I am using I18n and other related modules for my website as it is created in English but is being used in French also. I am using translations provided. My issue is that I have string translations but for some strings, text is not being translated, although the translations are available in the drupal. UPDATE After going ...

Also ask

We use cookies to deliver the best possible experience on our website. By continuing to use this site, accepting or closing this box, you consent to our use of cookies. To learn more, visit our privacy policy.