You are here

public static function Lingotek::convertDrupal2Lingotek in Lingotek Translation 7.2

Same name and namespace in other branches
  1. 7.7 lib/Drupal/lingotek/Lingotek.php \Lingotek::convertDrupal2Lingotek()
  2. 7.3 lib/Drupal/lingotek/Lingotek.php \Lingotek::convertDrupal2Lingotek()
  3. 7.4 lib/Drupal/lingotek/Lingotek.php \Lingotek::convertDrupal2Lingotek()
  4. 7.5 lib/Drupal/lingotek/Lingotek.php \Lingotek::convertDrupal2Lingotek()
  5. 7.6 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.

10 calls to Lingotek::convertDrupal2Lingotek()
Lingotek::testConvertFunctions in lib/Drupal/lingotek/Lingotek.php
LingotekApi::getCommentCreateWithTargetsParams in lib/Drupal/lingotek/LingotekApi.php
Gets the comment-specific parameters for use in a createContentDocumentWithTargets API call.
lingotek_enable_language_by_code in ./lingotek.util.inc
lingotek_form_node_form_alter in ./lingotek.module
Implements hook_form_BASE_FORM_ID_alter().
lingotek_get_localization_languages_json in ./lingotek.dashboard.inc
Outputs the languages active in this installation. Supplied to the dashboard. Output Format: ["en","es"]

... See full list

File

lib/Drupal/lingotek/Lingotek.php, line 233
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;
      }
      else {
        if (isset(self::$language_map[$drupal_language_code])) {
          $lingotek_locale = self::$language_map[$drupal_language_code];
        }
      }
    }

    //dvz($lingotek_locale,TRUE);
    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;
}