You are here

class LanguageLocaleMapper in Lingotek Translation 4.0.x

Same name and namespace in other branches
  1. 8 src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper
  2. 8.2 src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper
  3. 3.0.x src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper
  4. 3.1.x src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper
  5. 3.2.x src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper
  6. 3.3.x src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper
  7. 3.4.x src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper
  8. 3.5.x src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper
  9. 3.6.x src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper
  10. 3.7.x src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper
  11. 3.8.x src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper

Hierarchy

Expanded class hierarchy of LanguageLocaleMapper

1 string reference to 'LanguageLocaleMapper'
lingotek.services.yml in ./lingotek.services.yml
lingotek.services.yml
1 service uses LanguageLocaleMapper
lingotek.language_locale_mapper in ./lingotek.services.yml
Drupal\lingotek\LanguageLocaleMapper

File

src/LanguageLocaleMapper.php, line 8

Namespace

Drupal\lingotek
View source
class LanguageLocaleMapper implements LanguageLocaleMapperInterface {

  /**
   * The Entity Type Manager service.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a new LingotekConfigTranslationService object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
  }

  /**
   * {@inheritDoc}
   */
  public function getConfigurableLanguageForLocale($locale) {
    $drupal_language = NULL;
    $locale = str_replace("-", "_", $locale);
    $id = $this->entityTypeManager
      ->getStorage('configurable_language')
      ->getQuery()
      ->condition('third_party_settings.lingotek.locale', $locale)
      ->execute();
    if (!empty($id)) {
      $drupal_language = ConfigurableLanguage::load(reset($id));
    }
    else {
      $drupal_language = ConfigurableLanguage::load(LingotekLocale::convertLingotek2Drupal($locale));
    }
    return $drupal_language;
  }

  /**
   * {@inheritDoc}
   */
  public function getLocaleForLangcode($langcode) {

    /** @var \Drupal\language\ConfigurableLanguageInterface $config_language */
    $config_language = ConfigurableLanguage::load($langcode);
    $locale = NULL;
    if ($config_language) {
      $locale = $config_language
        ->getThirdPartySetting('lingotek', 'locale', LingotekLocale::convertDrupal2Lingotek($langcode));
    }
    return $locale;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
LanguageLocaleMapper::$entityTypeManager protected property The Entity Type Manager service.
LanguageLocaleMapper::getConfigurableLanguageForLocale public function Gets the Drupal language for the given Lingotek locale. Overrides LanguageLocaleMapperInterface::getConfigurableLanguageForLocale
LanguageLocaleMapper::getLocaleForLangcode public function Gets the Lingotek locale for the given Drupal langcode. Overrides LanguageLocaleMapperInterface::getLocaleForLangcode
LanguageLocaleMapper::__construct public function Constructs a new LingotekConfigTranslationService object.