0
$links['node']['#links']['node-readmore']['attributes']['title'] = 

$entity->field_anc_label->getString();

I am using getString() value , need to know whether its translated or we need to call it under t() to get it translated ?

| improve this question | | | | |
1

you can check translation with something like

if ($entity->get('field_anc_label')->getFieldDefinition()->isTranslatable()) {
  // The field translation is enabled.
$links['node']['#links']['node-readmore']['attributes']['title'] = $entity->field_anc_label->getString();
}else{
$links['node']['#links']['node-readmore']['attributes']['title'] = 
t($entity->field_anc_label->getString());
}
| improve this answer | | | | |
0

t() is for translation of string literals in UI. To translate content you have to use Entity Translation.

In this case for example:

$translated_entity = \Drupal::service('entity.repository')
  ->getTranslationFromCon‌​text($entity);

$links['node']['#links']['node-readmore']['attributes']['title'] = 
  $translated_entity->field_anc_label->value;
| improve this answer | | | | |

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.