public function Translator::getSupportedTargetLanguages

Returns the supported target languages for this translator.

Parameters

string $source_language: The local source language.

Return value

array An array of supported target languages in ISO format.

Overrides TranslatorInterface::getSupportedTargetLanguages

File

src/Entity/Translator.php, line 286

Class

Translator
Entity class for the tmgmt_translator entity.

Namespace

Drupal\tmgmt\Entity

Code

public function getSupportedTargetLanguages($source_language) {
  if ($plugin = $this
    ->getPlugin()) {
    $info = $plugin
      ->getPluginDefinition();
    if (isset($info['language_cache']) && empty($info['language_cache'])) {

      // This plugin doesn't support language caching.
      return $this
        ->mapToLocalLanguages($plugin
        ->getSupportedTargetLanguages($this, $this
        ->mapToRemoteLanguage($source_language)));
    }
    else {

      // Retrieve the supported languages from the cache.
      if (empty($this->languageCache) && ($cache = \Drupal::cache('data')
        ->get('tmgmt_languages:' . $this->name))) {
        $this->languageCache = $cache->data;
      }

      // Even if we successfully queried the cache it might not have an entry
      // for our source language yet.
      if (!isset($this->languageCache[$source_language])) {
        $local_languages = $this
          ->mapToLocalLanguages($plugin
          ->getSupportedTargetLanguages($this, $this
          ->mapToRemoteLanguage($source_language)));
        if (empty($local_languages)) {
          return [];
        }
        $this->languageCache[$source_language] = $local_languages;
        $this
          ->updateCache();
      }
    }
    return $this->languageCache[$source_language];
  }
}