public function LingotekApi::getTranslation in Lingotek Translation 3.0.x
Same name and namespace in other branches
- 8 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getTranslation()
- 8.2 src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getTranslation()
- 4.0.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getTranslation()
- 3.1.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getTranslation()
- 3.2.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getTranslation()
- 3.3.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getTranslation()
- 3.4.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getTranslation()
- 3.5.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getTranslation()
- 3.6.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getTranslation()
- 3.7.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getTranslation()
- 3.8.x src/Remote/LingotekApi.php \Drupal\lingotek\Remote\LingotekApi::getTranslation()
Gets a document target translation for a given locale from the Lingotek service.
Parameters
string $id: The document id.
string $locale: The target locale.
bool $useSource: (Optional) Flag indicating if should return the source if this is not yet translated. By default is FALSE.
Return value
\Psr\Http\Message\ResponseInterface A response.
Overrides LingotekApiInterface::getTranslation
File
- src/
Remote/ LingotekApi.php, line 294
Class
- LingotekApi
- A simple connector to the Lingotek Translation API.
Namespace
Drupal\lingotek\RemoteCode
public function getTranslation($id, $locale, $useSource = FALSE) {
try {
$this->logger
->debug('Lingotek::getTranslation called with id ' . $id . ' and locale ' . $locale);
$response = $this->lingotekClient
->get('/api/document/' . $id . '/content', [
'locale_code' => $locale,
'use_source' => $useSource ? 'true' : 'false',
]);
} catch (\Exception $e) {
$this->logger
->error('Error getting translation (%id, %locale): %message.', [
'%id' => $id,
'%locale' => $locale,
'%message' => $e
->getMessage(),
]);
throw new LingotekApiException('Failed to add translation: ' . $e
->getMessage());
}
$this->logger
->debug('getTranslation response received, code %code and body %body', [
'%code' => $response
->getStatusCode(),
'%body' => (string) $response
->getBody(TRUE),
]);
return $response;
}