public function Translator::mapToLocalLanguages

Maps remote languages to local languages.

Returns a list of local languages that can be mapped to any of the remote languages.

Parameters

string[] $remote_languages: Remote language codes.

Return value

string[] Local language codes.

Overrides TranslatorInterface::mapToLocalLanguages

1 call to Translator::mapToLocalLanguages()
Translator::getSupportedTargetLanguages in src/Entity/Translator.php
Returns the supported target languages for this translator.

File

src/Entity/Translator.php, line 416

Class

Translator
Entity class for the tmgmt_translator entity.

Namespace

Drupal\tmgmt\Entity

Code

public function mapToLocalLanguages(array $remote_languages) {
  $local_languages = array();
  $remote_mappings = $this
    ->getPlugin()
    ->getDefaultRemoteLanguagesMappings();
  foreach ($remote_languages as $language => $info) {
    if (in_array($language, $remote_mappings)) {
      $local_language = array_search($language, $remote_mappings);
      $local_languages[$local_language] = $local_language;
    }
    else {
      $local_languages[$language] = $this
        ->mapToRemoteLanguage($language);
    }
  }
  foreach (\Drupal::languageManager()
    ->getLanguages() as $language => $info) {
    $remote_language = $this
      ->mapToRemoteLanguage($language);
    if (isset($remote_languages[$remote_language])) {
      $local_languages[$language] = $language;
    }
  }
  return $local_languages;
}