You are here

public static function LingotekLocale::convertLingotek2Drupal in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  2. 4.0.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  3. 3.0.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  4. 3.1.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  5. 3.2.x src/LingotekLocale.php \Drupal\lingotek\LingotekLocale::convertLingotek2Drupal()
  6. 3.3.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 src/Tests/LingotekLocaleTest.php
LingotekManagementForm::getSourceStatus in src/Form/LingotekManagementForm.php
Gets the source status of an entity in a format ready to display.

File

src/LingotekLocale.php, line 264
Defines LingotekLocale class.

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();
  $drupal_language_code = strtolower(str_replace("_", "-", $lingotek_locale));

  // standard conversion
  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;
}