You are here

function lingotek_entity_langcode in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.5 lingotek.util.inc \lingotek_entity_langcode()
  2. 7.6 lingotek.util.inc \lingotek_entity_langcode()
4 calls to lingotek_entity_langcode()
lingotek_delete_field_translations in ./lingotek.util.inc
Delete translations for field based entities
lingotek_entity_locale in ./lingotek.util.inc
lingotek_entity_translation_delete_translations in ./lingotek.util.inc
Delete local translations from the Entity Translation table
lingotek_entity_translation_save_status in ./lingotek.util.inc
Save a translation to the Entity Translation table with status and additional parameters

File

./lingotek.util.inc, line 2617
Utility functions.

Code

function lingotek_entity_langcode($entity_type, $entity) {

  // Assume all bean content is created in the site's default language.
  if ($entity_type == 'bean') {
    return lingotek_get_bean_source($entity->bid);
  }

  // Get the group source language. Sometimes the gid for a group isn't present.
  if ($entity_type == 'group') {
    if (isset($entity->gid)) {
      $source_language = lingotek_get_group_source($entity->gid);
    }
    else {
      $source_language = isset($entity->language) ? $entity->language : NULL;
    }
    return $source_language;
  }
  if ($entity_type == 'paragraphs_item') {
    return lingotek_get_paragraphs_item_source($entity->item_id);
  }
  if ($entity_type == 'file') {
    return lingotek_get_file_source($entity->fid);
  }
  $info = entity_get_info($entity_type);

  // Default to string 'language' if no language-related entity key is found.
  $lang_key = !empty($info['entity keys']['language']) ? $info['entity keys']['language'] : 'language';
  return !empty($entity->{$lang_key}) ? $entity->{$lang_key} : NULL;
}