I have a node. I render it like this:

$render_controller = \Drupal::entityManager()->getViewBuilder($node->getEntityTypeId());
$render_output = $render_controller->view($node);
echo \Drupal::service("renderer")->render($render_output);

The rendered field labels are always in the original language ("de"). Even if I use this before:


I find it really excruciatingly difficult to get translated labels to render properly. I've searched through the source code all the way from back to front to find an answer. I see my translated field label in the frontend under "/admin/config/regional/config-translation/node_fields" so it must be stored somewhere. But how do I access it or even better render the whole field correctly? Using $field->getLabel() etc didn't help either. And neither did $language_manager->setConfigOverrideLanguage($language); Somehow Drupal must think it's very clever and uses some default language I don't want. I want to pick a specific language and render that. And I would expect that using getTranslation() on the node really gives you everything in the right language. Somehow it doesn't. Why?


You have the change the current config translation language. user_mail() has an example for that:

  $language_manager = \Drupal::languageManager();

  $language = $language_manager->getLanguage('en');
  $original_language = $language_manager->getConfigOverrideLanguage();

  // Do your thing here.

  • Thank you for your answer, Berdir. This is exactly what I'm doing: <code> $language_manager = \Drupal::languageManager(); $language = $language_manager->getLanguage('en'); $original_language = $language_manager->getConfigOverrideLanguage(); $language_manager->setConfigOverrideLanguage($language); $view=$myvalue->view("default"); echo strval(\Drupal::service("renderer")->render($view)); $language_manager->setConfigOverrideLanguage($original_language); </code> It doesn't work. – rgpublic Jul 6 '16 at 10:56
  • Huh. Sorry for the excessive editing/spam but how the heck can I create a reply with properly formatted code in it? And why oh why did anyone think it's a create idea to use just the Enter key for posting? Argh. Totally counterintuitive. Sigh. – rgpublic Jul 6 '16 at 11:06

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.