You are here

public function SmartlingTranslator::getSupportedRemoteLanguages in TMGMT Translator Smartling 8.2

Same name and namespace in other branches
  1. 8.4 src/Plugin/tmgmt/Translator/SmartlingTranslator.php \Drupal\tmgmt_smartling\Plugin\tmgmt\Translator\SmartlingTranslator::getSupportedRemoteLanguages()
  2. 8 src/Plugin/tmgmt/Translator/SmartlingTranslator.php \Drupal\tmgmt_smartling\Plugin\tmgmt\Translator\SmartlingTranslator::getSupportedRemoteLanguages()
  3. 8.3 src/Plugin/tmgmt/Translator/SmartlingTranslator.php \Drupal\tmgmt_smartling\Plugin\tmgmt\Translator\SmartlingTranslator::getSupportedRemoteLanguages()

Gets all supported languages of the translator.

This list of all language codes used by the remote translator is then used for example in the translator settings form to select which remote language code correspond to which local language code.

Parameters

TranslatorInterface $translator: Translator entity for which to get supported languages.

Return value

array An array of language codes which are provided by the translator (remote language codes).

Overrides TranslatorPluginBase::getSupportedRemoteLanguages

1 call to SmartlingTranslator::getSupportedRemoteLanguages()
SmartlingTranslator::getSupportedTargetLanguages in src/Plugin/tmgmt/Translator/SmartlingTranslator.php
Returns all available target languages that are supported by this service when given a source language.

File

src/Plugin/tmgmt/Translator/SmartlingTranslator.php, line 212
Contains \Drupal\tmgmt_smartling\Plugin\tmgmt\Translator\SmartlingTranslator.

Class

SmartlingTranslator
Smartling translator plugin.

Namespace

Drupal\tmgmt_smartling\Plugin\tmgmt\Translator

Code

public function getSupportedRemoteLanguages(TranslatorInterface $translator) {
  $languages = [];

  // Prevent access if the translator isn't configured yet.
  if (!$translator
    ->getSetting('project_id')) {

    // @todo should be implemented by an Exception.
    return $languages;
  }
  try {
    $smartling_project_details = $this
      ->getApi($translator, 'project')
      ->getProjectDetails();
    foreach ($smartling_project_details['targetLocales'] as $language) {
      $languages[$language['localeId']] = $language['localeId'];
    }
  } catch (\Exception $e) {
    Drupal::logger('tmgmt_smartling')
      ->error('Can not get languages from the translator: @message', [
      '@message' => $e
        ->getMessage(),
    ]);
    return $languages;
  }
  return $languages;
}