You are here

function lingotek_entity_view_redirect in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.5 lingotek.page.inc \lingotek_entity_view_redirect()
  2. 7.6 lingotek.page.inc \lingotek_entity_view_redirect()

This is a function that redirects to the entity specified for a particular lingotek locale (e.g., en_US, de_DE, fr_FR)

1 string reference to 'lingotek_entity_view_redirect'
lingotek_menu in ./lingotek.module
Implements hook_menu().

File

./lingotek.page.inc, line 685
Lingotek Tab for Nodes

Code

function lingotek_entity_view_redirect($entity_type, $entity_id, $lingotek_locale) {
  $drupal_languages = language_list();
  $drupal_language_code = Lingotek::convertLingotek2Drupal($lingotek_locale, TRUE);
  $language = isset($drupal_languages[$drupal_language_code]) ? $drupal_languages[$drupal_language_code] : language_default();
  $entity = entity_load_single($entity_type, $entity_id);
  if (!$entity) {
    drupal_not_found();
  }

  // check for node-based target translation
  if (lingotek_uses_node_translation($entity)) {
    $target_nodes = lingotek_node_get_translations($entity_id);
    foreach ($target_nodes as $langcode => $node_info) {
      if ($drupal_language_code == $langcode) {

        // re-set entity to the target node instead of the source node
        $entity_id = $target_nodes[$langcode]->nid;
        $entity = entity_load_single($entity_type, $entity_id);
        continue;
      }
    }
  }
  $entity_uri = entity_uri($entity_type, $entity);
  $path = $entity_uri['path'];
  $url_language_detection_enabled = TRUE;

  //TO-DO: detect when it is not enabled, currently it is assumed
  $options = array(
    'language' => $language,
  );
  locale_language_url_rewrite_url($path, $options);
  drupal_goto($path, $options);
}