You are here

public static function LingotekLocale::generateLingotek2Drupal in Lingotek Translation 3.5.x

Same name and namespace in other branches
  1. 8 src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::generateLingotek2Drupal()
  2. 8.2 src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::generateLingotek2Drupal()
  3. 4.0.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::generateLingotek2Drupal()
  4. 3.0.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::generateLingotek2Drupal()
  5. 3.1.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::generateLingotek2Drupal()
  6. 3.2.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::generateLingotek2Drupal()
  7. 3.3.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::generateLingotek2Drupal()
  8. 3.4.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::generateLingotek2Drupal()
  9. 3.6.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::generateLingotek2Drupal()
  10. 3.7.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::generateLingotek2Drupal()
  11. 3.8.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::generateLingotek2Drupal()
2 calls to LingotekLocale::generateLingotek2Drupal()
LingotekDashboardController::endpoint in src/Controller/LingotekDashboardController.php
LingotekLocaleTest::testGenerateLingotek2Drupal in tests/src/Functional/LingotekLocaleTest.php

File

src/LingotekLocale.php, line 282

Class

LingotekLocale
A utility class for Lingotek translation.

Namespace

Drupal\lingotek

Code

public static function generateLingotek2Drupal($lingotek_locale) {

  // standard conversion
  $drupal_language_code = strtolower(str_replace("_", "-", $lingotek_locale));
  if ($hyphen_index = strpos($drupal_language_code, '-') > 0) {
    $drupal_general_code = substr($drupal_language_code, 0, strpos($drupal_language_code, '-'));
  }
  else {

    // We try with the given language, if we didn't have an hyphen (e.g. ar).
    $drupal_general_code = $drupal_language_code;
  }

  // check enabled list
  $enabled_languages = \Drupal::languageManager()
    ->getLanguages();
  $enabled_codes = array_keys($enabled_languages);
  if (!in_array($drupal_general_code, $enabled_codes)) {
    return $drupal_general_code;
  }
  elseif (!in_array($drupal_language_code, $enabled_codes)) {
    return $drupal_language_code;
  }
  else {
    return $drupal_language_code . rand(10, 99);
  }
}