You are here

public function GlobalLinkTranslator::getSupportedLanguagePairs in GlobalLink Connect for Drupal 8.2

Same name and namespace in other branches
  1. 8 src/Plugin/tmgmt/Translator/GlobalLinkTranslator.php \Drupal\globallink\Plugin\tmgmt\Translator\GlobalLinkTranslator::getSupportedLanguagePairs()

Default implementation that gets target languages for each remote language. This approach is ineffective and therefore it is advised that a plugin should provide own implementation.

Overrides TranslatorPluginBase::getSupportedLanguagePairs

File

src/Plugin/tmgmt/Translator/GlobalLinkTranslator.php, line 647

Class

GlobalLinkTranslator
GlobalLink translation plugin controller.

Namespace

Drupal\globallink\Plugin\tmgmt\Translator

Code

public function getSupportedLanguagePairs(TranslatorInterface $translator) {
  $language_pairs = [];
  try {
    $this
      ->setTranslator($translator);
    $settings = $this->translator
      ->getSettings();
    $pd_config = $this->glExchangeAdapter
      ->getPDConfig($settings);
    $glexchange = $this->glExchangeAdapter
      ->getGlExchange($pd_config);
    $supported = $glexchange
      ->getProject($settings['pd_projectid'])->languageDirections;

    // Build a mapping of source and target language pairs.
    foreach ($supported as $pair) {
      $language_pairs[] = [
        'source_language' => $pair->sourceLanguage,
        'target_language' => $pair->targetLanguage,
      ];
    }
  } catch (\Exception $e) {
    return [];
  }
  return $language_pairs;
}