1

I use entity_translation to translate node body field, so in a fully loaded node object body is an array of 2 languages ('en' and 'ru').

For specific node type I would like to render body in both languages one after another:

Russian version of node body

English version of node body

so switching between translations will not be needed.

What hook can I use to achieve this?

In implementation of hook_node_load() body is an array of 2 languages, but in hook_node_view_alter() body already contains only the current language value.

When using node_load() in hook_preprocess_node, it retrieves the node object from cache and its body has only one (current) language value.

1

I found a solution: call field_attach_view with the required language.

/**
 * Implements hook_preprocess_node().
 */
function MYMODULE_preprocess_node(&$vars) {
  if ($GLOBALS['language']->language == 'ru') {
    $original_langcode = 'en';
    $content_original = field_attach_view('node', $vars['node'], $vars['view_mode'], $original_langcode);

    // need to check if languages match, it may be a language fallback
    if ($content_original['body']['#language'] == $original_langcode) {
      $vars['content']['body_original'] = $content_original['body']
    }
  }
}

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.