-1

I am building a bilingual site with Drupal 10 and I am using views to show content items listings. In my views I am using field: Custom text to format the teasers of each item the way I want.

I have translated all the fields of my content types and my issue is how to show in the custom text each field's label.

Here is how my view's configuration looks like: enter image description here

Here is an example of such a custom text:

<div class="col-sm-12 teaser-wrapper">
    <div class="teaser-image">{{ field_image }}</div>
    <div class="teaser-header">{{ title }}</div>
    <div class="teaser-text">{{ body }}</div>
    <div class="row teaser-field">
        <div class="col-xs-12 col-sm-12 teaser-field">
                <span class="lbl">Location: </span>
                <span class="val">{{ field_region }}</span>
        </div>
        <div class="col-xs-12 col-sm-12 teaser-field">
                <span class="lbl">Path Length: </span>
                <span class="val">{{ field_path_length }}</span>
        </div>
        <div class="col-xs-12 col-sm-12 teaser-field">
                <span class="lbl">Activities: </span>
                <span class="val">{{ field_nature_activities }}</span>
        </div>
    </div>
</div>

As you can see at the moment I am just using hardcoded values for the labels.

How can I print their translated values?

3
  • Have you tried <span class="lbl">{{ 'Location'|t }}: </span>?
    – leymannx
    Oct 5 at 10:44
  • No, but what exactly 'Location' is supposed to be? I have tried with using custom field's label (which is translated) without luck.
    – thanili
    Oct 5 at 11:13
  • I don't understand why this question has been downvoted. Some of us are new to Drupal; so do you expect from us to be able in a couple of months to have deep knowledge on all of it's aspects and different concepts? Does my question show lack of effort or is not clear? I have searched the web for an answer and read dozens of posts and documents relevant with Drupal views before posting. Why do "you" penalize people for asking when their aim is just to acquire knowledge? Have "you" born with the knowledge or is it a privilege that you need to pay in order to get?
    – thanili
    Oct 5 at 13:38

1 Answer 1

0

You can use

<span class="lbl">{% trans %}Location{% endtrans %}: </span>
3
  • Thanks, but what exactly 'Location' is supposed to be? Original's custom field label? A custom label that I can create somehow and then translate?
    – thanili
    Oct 5 at 11:12
  • Yes, a custom label from your question code. You can translate it
    – Vanish
    Oct 5 at 12:08
  • Thanks, I will try it
    – thanili
    Oct 5 at 13:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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