You are here

public function GoogleTranslator::getSupportedRemoteLanguages in TMGMT Translator Google 8

Overrides TMGMTDefaultTranslatorPluginController::getSupportedRemoteLanguages().

Overrides TranslatorPluginBase::getSupportedRemoteLanguages

1 call to GoogleTranslator::getSupportedRemoteLanguages()
GoogleTranslator::getSupportedTargetLanguages in src/Plugin/tmgmt/Translator/GoogleTranslator.php
Overrides TMGMTDefaultTranslatorPluginController::getSupportedTargetLanguages().

File

src/Plugin/tmgmt/Translator/GoogleTranslator.php, line 176
Contains \Drupal\tmgmt_microsoft\Plugin\tmgmt\Translator\MicrosoftTranslator.

Class

GoogleTranslator
Google translator plugin.

Namespace

Drupal\tmgmt_google\Plugin\tmgmt\Translator

Code

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

  // Prevent access if the translator isn't configured yet.
  if (!$translator
    ->getSetting('api_key')) {
    return $languages;
  }
  try {
    $request = $this
      ->doRequest($translator, 'languages');
    if (isset($request['data'])) {
      foreach ($request['data']['languages'] as $language) {
        $languages[$language['language']] = $language['language'];
      }
    }
  } catch (\Exception $e) {
    \Drupal::messenger()
      ->addMessage($e
      ->getMessage(), 'error');
    return $languages;
  }
  return $languages;
}