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>
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | bootstrap_barrio-add-t-filter-for-Label_8.x-4.x-3018074.patch | 646 bytes | npralhad |
Comments
Comment #2
npralhad commentedAdded the t filter.
Comment #3
hatuhay commentedComment #5
cqbent commentedI'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.
Comment #7
carles.zapater commentedThis 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.
Comment #8
crifi commentedI can confirm, that this commit/patch breaks the translation API of Drupal 8 and results in the TranslatableMarkup exception. Please revert it.
Comment #9
carles.zapater commentedTranslation 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.
Comment #10
carles.zapater commentedVersion 8.x-4.20 with the same problem.
Comment #12
hatuhay commentedComment #14
npralhad commented