You are here

public function LingotekEntity::setLanguage in Lingotek Translation 7.7

Same name and namespace in other branches
  1. 7.6 lib/Drupal/lingotek/LingotekEntity.php \LingotekEntity::setLanguage()

Set the entity's language to be used by Lingotek, which will sometimes be different from the stated Drupal language.

1 call to LingotekEntity::setLanguage()
LingotekEntity::__construct in lib/Drupal/lingotek/LingotekEntity.php
Constructor.

File

lib/Drupal/lingotek/LingotekEntity.php, line 486
Defines LingotekEntity.

Class

LingotekEntity
A class wrapper for Lingotek-specific behavior on nodes.

Code

public function setLanguage($language = NULL) {
  if (empty($language)) {
    if ($this->entity_type == 'bean') {
      $language = language_default()->language;
    }
    elseif ($this->entity_type == 'group') {
      $language = lingotek_get_group_source($this->entity->gid);
    }
    elseif ($this->entity_type == 'paragraphs_item') {
      $language = lingotek_get_paragraphs_item_source($this->entity->item_id);
    }
    elseif ($this->entity_type == 'file') {
      $language = lingotek_get_file_source($this->entity->fid);
    }
    else {
      $drupal_locale = Lingotek::convertDrupal2Lingotek($this->entity->language);
      if (!empty($this->entity->lingotek['allow_source_overwriting']) && !empty($this->entity->lingotek['source_language_' . $drupal_locale])) {
        $language = $this->entity->lingotek['source_language_' . $drupal_locale];
      }
      else {
        $language = $this->entity->language;
      }
    }
  }
  $this->language = $language;
  $this->locale = Lingotek::convertDrupal2Lingotek($this->language);
  $this->language_targets = Lingotek::getLanguagesWithoutSource($this->locale);
}