You are here

class LanguageLocaleMapper in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/LanguageLocaleMapper.php \Drupal\lingotek\LanguageLocaleMapper
  2. 4.0.x 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 11

Namespace

Drupal\lingotek
View source
class LanguageLocaleMapper implements LanguageLocaleMapperInterface {

  /**
   * The entity query factory service.
   *
   * @var \Drupal\Core\Entity\Query\QueryFactory
   */
  protected $entityQuery;

  /**
   * Constructs a new LingotekConfigTranslationService object.
   *
   * @param \Drupal\Core\Entity\Query\QueryFactory $entity_query
   *   The entity query factory.
   */
  public function __construct(QueryFactory $entity_query) {
    $this->entityQuery = $entity_query;
  }

  /**
   * {@inheritDoc}
   */
  public function getConfigurableLanguageForLocale($locale) {
    $drupal_language = NULL;
    $locale = str_replace("-", "_", $locale);
    $id = $this->entityQuery
      ->get('configurable_language')
      ->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 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::$entityQuery protected property The entity query factory 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.