You are here

function entity_translation_get_existing_language in Entity Translation 7

Determines an existing translation language.

Based on the requested language and the translations available for the given entity, determines an existing translation language. This takes into account language fallback rules.

Parameters

$entity_type: The type of the entity.

$entity: The entity whose existing translation language has to be returned.

$langcode: (optional) The requested language code. Defaults to the current content language.

Return value

A valid language code.

3 calls to entity_translation_get_existing_language()
entity_translation_edit_access in ./entity_translation.module
Access callback.
entity_translation_edit_page in ./entity_translation.module
Page callback.
entity_translation_form_language in ./entity_translation.module
Determines the current form language.

File

./entity_translation.module, line 650

Code

function entity_translation_get_existing_language($entity_type, $entity, $langcode = NULL) {
  $handler = entity_translation_get_handler($entity_type, $entity);
  if (empty($langcode)) {
    $langcode = $GLOBALS['language_content']->language;
  }
  $translations = $handler
    ->getTranslations();
  $fallback = drupal_multilingual() ? language_fallback_get_candidates() : array(
    LANGUAGE_NONE,
  );
  while (!empty($langcode) && !isset($translations->data[$langcode])) {
    $langcode = array_shift($fallback);
  }

  // If no translation is available fall back to the entity language.
  return !empty($langcode) ? $langcode : $handler
    ->getLanguage();
}