You are here

public static function LingotekLocale::convertLingotek2Drupal in Lingotek Translation 3.3.x

Same name and namespace in other branches
  1. 8 src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  2. 8.2 src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  3. 4.0.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  4. 3.0.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  5. 3.1.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  6. 3.2.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  7. 3.4.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  8. 3.5.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  9. 3.6.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  10. 3.7.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  11. 3.8.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::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')

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.

4 calls to LingotekLocale::convertLingotek2Drupal()
LanguageLocaleMapper::getConfigurableLanguageForLocale in src/LanguageLocaleMapper.php
Gets the Drupal language for the given Lingotek locale.
LingotekLocale::testConvertFunctions in src/LingotekLocale.php
LingotekLocaleTest::testConvertDrupal2Lingotek in tests/src/Functional/LingotekLocaleTest.php
LingotekManagementFormBase::getSourceStatus in src/Form/LingotekManagementFormBase.php
Gets the source status of an entity in a format ready to display.

File

src/LingotekLocale.php, line 261

Class

LingotekLocale
A utility class for Lingotek translation.

Namespace

Drupal\lingotek

Code

public static function convertLingotek2Drupal($lingotek_locale, $generate = FALSE) {
  $installed_languages = \Drupal::languageManager()
    ->getLanguages();

  // standard conversion
  $drupal_language_code = strtolower(str_replace("_", "-", $lingotek_locale));
  if (isset($installed_languages[$drupal_language_code])) {
    return $installed_languages[$drupal_language_code]
      ->getId();
  }
  $drupal_general_code = substr($drupal_language_code, 0, strpos($drupal_language_code, '-'));
  $exceptions = self::$language_mapping_l2d_exceptions;
  if (array_key_exists($lingotek_locale, $exceptions)) {
    return $exceptions[$lingotek_locale];
  }
  else {
    $flipped_map = array_flip(self::$language_map);
    if (isset($flipped_map[$lingotek_locale])) {
      return $flipped_map[$lingotek_locale];
    }
  }
  return $drupal_general_code;
}