You are here

public function LingotekApi::getLocales in Lingotek Translation 8

Same name and namespace in other branches
  1. 8.2 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getLocales()
  2. 4.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getLocales()
  3. 3.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getLocales()
  4. 3.1.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getLocales()
  5. 3.2.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getLocales()
  6. 3.3.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getLocales()
  7. 3.4.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getLocales()
  8. 3.5.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getLocales()
  9. 3.6.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getLocales()
  10. 3.7.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getLocales()
  11. 3.8.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getLocales()

Get the available locales on Lingotek.

Return value

array|bool Array of locales (as in de-DE, es-ES). FALSE if there is an error.

Overrides LingotekApiInterface::getLocales

File

src/Remote/LingotekApi.php, line 49
Contains \Drupal\lingotek\Remote\LingotekApi.

Class

LingotekApi

Namespace

Drupal\lingotek\Remote

Code

public function getLocales() {
  $this->logger
    ->debug('Starting Locales request: /api/locale with args [limit => 1000]');

  /** @var ResponseInterface $response */
  try {
    $response = $this->lingotekClient
      ->get('/api/locale', [
      'limit' => 1000,
    ]);
    if ($response
      ->getStatusCode() == Response::HTTP_OK) {
      $data = json_decode($response
        ->getBody(), TRUE);
      $this->logger
        ->debug('getLocales response received, code %code and body %body', [
        '%code' => $response
          ->getStatusCode(),
        '%body' => (string) $response
          ->getBody(TRUE),
      ]);
      return $data;
    }
  } catch (\Exception $e) {
    $this->logger
      ->error('Error requesting locales: %message.', [
      '%message' => $e
        ->getMessage(),
    ]);
    throw new LingotekApiException('Error requesting locales: ' . $e
      ->getMessage());
  }
  return FALSE;
}