You are here

public static function Lingotek::convertDrupal2Lingotek in Lingotek Translation 7.6

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

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

Parameters

string $drupal_language_code: A Drupal language code.

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

Return value

mixed The Lingotek language code if there is a match for the passed language code, FALSE otherwise.

29 calls to Lingotek::convertDrupal2Lingotek()
Lingotek::isSupportedLanguage in lib/Drupal/lingotek/Lingotek.php
Returns whether the given language is supported.
Lingotek::testConvertFunctions in lib/Drupal/lingotek/Lingotek.php
LingotekConfigSet::__construct in lib/Drupal/lingotek/LingotekConfigSet.php
Constructor.
LingotekEntity::getSourceLocale in lib/Drupal/lingotek/LingotekEntity.php
LingotekEntity::setLanguage in lib/Drupal/lingotek/LingotekEntity.php
Set the entity's language to be used by Lingotek, which will sometimes be different from the stated Drupal language.

... See full list

File

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

Class

Lingotek
A utility class for Lingotek translation.

Code

public static function convertDrupal2Lingotek($drupal_language_code, $enabled_check = TRUE) {
  $lingotek_locale = FALSE;

  // standard conversion
  if (!$enabled_check) {

    // If the code contains a dash then, keep it specific
    $exceptions = self::$language_mapping_d2l_exceptions;
    if (array_key_exists($drupal_language_code, $exceptions)) {
      $lingotek_locale = $exceptions[$drupal_language_code];
    }
    else {
      $dash_pos = strpos($drupal_language_code, "-");
      if ($dash_pos !== FALSE) {
        $lang = substr($drupal_language_code, 0, $dash_pos);
        $loc = strtoupper(substr($drupal_language_code, $dash_pos + 1));
        $lingotek_locale = $lang . '_' . $loc;
      }
      elseif (isset(self::$language_map[$drupal_language_code])) {
        $lingotek_locale = self::$language_map[$drupal_language_code];
      }
    }
    return $lingotek_locale;
  }

  // check to see if the lingotek_locale is set the drupal languages table for this language
  $languages = language_list();
  foreach ($languages as $target) {
    if (strcasecmp($drupal_language_code, $target->language) == 0 && isset($target->lingotek_locale)) {
      return $target->lingotek_locale;
    }
  }
  return $lingotek_locale;
}