Label printed in [tempates/field/field.html.twig] is not supporting translation. *t* filter needs to be added to the label value.

Current code

    <div{{ title_attributes.addClass(title_classes) }}>{{ label }}</div>

and can be changed to

    <div{{ title_attributes.addClass(title_classes) }}>{{ label | t }}</div>

Comments

npralhad created an issue. See original summary.

npralhad’s picture

Added the t filter.

hatuhay’s picture

Status: Patch (to be ported) » Fixed

  • agiover committed 7759947 on 8.x-4.x authored by npralhad
    Issue #3018074 by npralhad: Label in templates/field/field.html.twig is...
cqbent’s picture

Status: Fixed » Active

I'm reopening this issue because adding the "t" filter to the label is causing a TranslatableMarkup error ($string must be a string) for a number of fields on my site. Specifically this happens when another module is already using the "t" filter to set the label. This is happening on my site with Display Suite custom fields and with Private Messages fields but I'm imagining it would affect others as well. I'm overwriting this template file with my own custom field template file in my child theme now to fix but his issue took me hours to finally figure out so hopefully its useful to others.

  • hatuhay committed 469850b on 8.x-4.x authored by cqbent
    Issue #3018074 by npralhad, hatuhay, cqbent: Label in templates/field/...
carles.zapater’s picture

This patch is causing a TranslatableMarkup error. I don't understand why this patch is necessary. Core system is responsible of doing translations in code, not in twig templates. My custom entities translates custom field labels well.
Please rollback to previous code. thanks.

crifi’s picture

I can confirm, that this commit/patch breaks the translation API of Drupal 8 and results in the TranslatableMarkup exception. Please revert it.

carles.zapater’s picture

Translation filters
trans
This filter (alternatively, t) will run the variable through the Drupal t() function, which will return a translated string. This filter should be used for any interface strings manually placed in the template that will appear for users.

carles.zapater’s picture

Version 8.x-4.20 with the same problem.

  • hatuhay committed d387846 on 8.x-4.x authored by npralhad
    Issue #3018074 by npralhad, carles.zapater: Label in templates/field/...
hatuhay’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

npralhad’s picture