0

I am using the paragraphs module. I have a field which contains a date and time e.g. for events, which is added by an author. For the output I use a paragraph-twig-file and I have this:

<div class="timeline-date">
    {{ content.field_date }}
</div>

In the backend of Drupal I created a custom time "D, d.m.Y - H:i". The output is right e.g. "Fri, 24.08.2018 - 17:14", but my site is in german and not english. So how, can I translate the day of week in german? In my case this solution is not working

4
  • Try add field date between **{% trans %} ** and {% endtrans %} – MrD Aug 24 '18 at 15:50
  • It is not working. I got the following error message: "<em class="placeholder">Twig_Error_Syntax</em>: The text to be translated with &quot;trans&quot; can only contain references to simple variables in <em class="placeholder">Drupal\Core\Template\TwigTransTokenParser-&gt;checkTransString()</em> (line <em class="placeholder">10</em> of <em class="placeholder">themes/custom/.../.../.../.../paragraph--timeline-item.html.twig</em>). <pre class="backtrace">Drupal\Core\Template\TwigTransTokenParser-&gt;parse(Object)" – lesley n. Aug 24 '18 at 16:19
  • Can you get timestamp of this field date? – MrD Aug 24 '18 at 16:29
  • @MrD Why? Or maybe I do not understand your question. An author fill out the field. It is not a created date or something like this. – lesley n. Aug 24 '18 at 16:34
0

In Twig, you can use built-in translation contexts. I had to output my dates in dutch format. The default formatting was:

{% set date = node.created.value|date("j") ~ ' ' ~ node.created.value|date("F") ~ ' ' ~ node.created.value|date("Y") %}
// now {{ date }} outputs: 8 August 2020

When I use translation contexts, it worked as expected:

{% set date = node.created.value|date("j") ~ ' ' ~ node.created.value|date("F")|t({}, {'context' : 'Long month name'}) ~ ' ' ~ node.created.value|date("Y") %}
// now {{ date }} outputs: 8 augustus 2020

More about translation contexts in Twig: https://stefvanlooveren.me/blog/translate-dates-twig-drupal-8

-1

You need to do something like below screenshot in my case i have translated months of date field in french language.

enter image description here

you have to search for day string for different language like fri ,replace the text for each language in text box then save to path admin/config/regional/translate

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.