You are here

public static function Lingotek::convertLingotek2Drupal in Lingotek Translation 7.3

Same name and namespace in other branches
  1. 7.7 lib/Drupal/lingotek/Lingotek.php \Lingotek::convertLingotek2Drupal()
  2. 7.2 lib/Drupal/lingotek/Lingotek.php \Lingotek::convertLingotek2Drupal()
  3. 7.4 lib/Drupal/lingotek/Lingotek.php \Lingotek::convertLingotek2Drupal()
  4. 7.5 lib/Drupal/lingotek/Lingotek.php \Lingotek::convertLingotek2Drupal()
  5. 7.6 lib/Drupal/lingotek/Lingotek.php \Lingotek::convertLingotek2Drupal()

Gets the Drupal language code for the specified Lingotek language code.

Parameters

string $lingotek_locale: A Lingotek language code. (e.g., 'de_DE', 'pt_BR', 'fr_FR')

bool $enabled_check: Whether or not the languages table should used for lookup (use the code in the table), otherwise perform the standard conversion (e.g., de_DE => de-de)

Return value

mixed The Drupal language code if there is a match for the passed language code, (e.g., 'de-de', 'pt-br',' fr-fr') FALSE otherwise.

12 calls to Lingotek::convertLingotek2Drupal()
Lingotek::testConvertFunctions in lib/Drupal/lingotek/Lingotek.php
LingotekComment::updateLocalContentByTarget in lib/Drupal/lingotek/LingotekComment.php
Updates the local content of $target_code with data from a Lingotek Document
LingotekConfigChunk::updateLocalContentByTarget in lib/Drupal/lingotek/LingotekConfigChunk.php
Updates the local content of $target_code with data from a Lingotek Document
LingotekSync::getDirtyChunkLids in lib/Drupal/lingotek/LingotekSync.php
LingotekSync::getTargetNodeCountByStatus in lib/Drupal/lingotek/LingotekSync.php

... See full list

File

lib/Drupal/lingotek/Lingotek.php, line 279
Defines Lingotek.

Class

Lingotek
A utility class for Lingotek translation.

Code

public static function convertLingotek2Drupal($lingotek_locale, $enabled_check = TRUE) {
  $drupal_language_code = strtolower(str_replace("_", "-", $lingotek_locale));

  // standard conversion
  $drupal_general_code = substr($drupal_language_code, 0, strpos($drupal_language_code, '-'));
  if (!$enabled_check) {
    $exceptions = self::$language_mapping_l2d_exceptions;
    if (array_key_exists($lingotek_locale, $exceptions)) {
      return $exceptions[$lingotek_locale];
    }
    return $drupal_general_code;
  }
  $ret = FALSE;

  // check to see if the lingotek_locale is set in the drupal languages table
  $languages = language_list();
  foreach ($languages as $target) {
    if (isset($target->lingotek_locale) && strcmp($target->lingotek_locale, $lingotek_locale) == 0) {
      return $target->language;
    }
  }
  $exists = array_key_exists($drupal_general_code, $languages);
  if ($exists) {
    $ret = $drupal_general_code;
  }

  // if neither the lingotek_locale is set nor the general code exists, then check the code mapping (degraded)
  $ltk_to_drupal = array_flip(self::$language_map);
  if (isset($ltk_to_drupal[$lingotek_locale])) {
    $drupal_language_code = $ltk_to_drupal[$lingotek_locale];
    $exists = array_key_exists($drupal_language_code, $languages);
    if ($exists) {
      $ret = $drupal_language_code;
    }
  }

  //echo "\n\n convertLingotek2Drupal: ".$lingotek_locale." => ".$ret." \n\n";
  return $ret;
}