You are here

public function Translator::mapToRemoteLanguage in Translation Management Tool 8

Maps local language to remote language.

Parameters

string $language: Local language code.

Return value

string Remote language code.

Overrides TranslatorInterface::mapToRemoteLanguage

3 calls to Translator::mapToRemoteLanguage()
Translator::getRemoteLanguagesMappings in src/Entity/Translator.php
Gets existing remote languages mappings.
Translator::getSupportedTargetLanguages in src/Entity/Translator.php
Returns the supported target languages for this translator.
Translator::mapToLocalLanguages in src/Entity/Translator.php
Maps remote languages to local languages.

File

src/Entity/Translator.php, line 439

Class

Translator
Entity class for the tmgmt_translator entity.

Namespace

Drupal\tmgmt\Entity

Code

public function mapToRemoteLanguage($language) {
  if (!$this
    ->providesRemoteLanguageMappings()) {
    return $language;
  }
  $mapping = $this
    ->get('remote_languages_mappings');
  $remote_languages = $this
    ->getSupportedRemoteLanguages();
  if (!empty($mapping) && array_key_exists($language, $mapping)) {
    if (empty($remote_languages) || array_key_exists($mapping[$language], $remote_languages)) {
      return $mapping[$language];
    }
  }
  $default_mappings = $this
    ->getPlugin()
    ->getDefaultRemoteLanguagesMappings();
  if (isset($default_mappings[$language])) {
    return $default_mappings[$language];
  }
  if ($matching_language = \Drupal::service('tmgmt.language_matcher')
    ->getMatchingLangcode($language, $remote_languages)) {
    return $matching_language;
  }
  return $language;
}