You are here

public function FileApi::downloadFile in TMGMT Translator Smartling 8.4

Same name and namespace in other branches
  1. 8.2 api-sdk-php/src/File/FileApi.php \Smartling\File\FileApi::downloadFile()
  2. 8.2 vendor/smartling/api-sdk-php/src/File/FileApi.php \Smartling\File\FileApi::downloadFile()
  3. 8.3 vendor/smartling/api-sdk-php/src/File/FileApi.php \Smartling\File\FileApi::downloadFile()

Downloads the requested file from Smartling.

It is important to check the HTTP response status code. If Smartling finds and returns the file normally, you will receive a 200 SUCCESS response. If you receive any other response status code than 200, the requested file will not be part of the response.

Parameters

string $fileUri: Value that uniquely identifies the downloaded file.

string $locale: A locale identifier as specified in project setup. If no locale is specified, original content is returned.

DownloadFileParameters $params: (optional) An associative array of additional options, with the following elements:

  • 'retrievalType': Determines the desired format for the download. Could be one of following values: pending|published|pseudo|contextMatchingInstrumented
  • 'includeOriginalStrings': Boolean that specifies whether Smartling will return the original string or an empty string where no translation is available.

Return value

string File content.

Throws

\Smartling\Exceptions\SmartlingApiException

See also

http://docs.smartling.com/pages/API/FileAPI/Download-File/

File

vendor/smartling/api-sdk-php/src/File/FileApi.php, line 134

Class

FileApi
Class FileApi

Namespace

Smartling\File

Code

public function downloadFile($fileUri, $locale = '', DownloadFileParameters $params = null) {
  if (!is_string($locale) || strlen($locale) < 2) {
    $message = vsprintf('Invalid locale value got. Expected a string of at least 2 chars length, but got: %s', [
      '' === $locale ? 'Empty string' : var_export($locale, true),
    ]);
    throw new SmartlingApiException($message);
  }
  $params = is_null($params) ? [] : $params
    ->exportToArray();
  $params['fileUri'] = $fileUri;
  $requestData = $this
    ->getDefaultRequestData('query', $params);
  unset($requestData['headers']['Accept']);
  return $this
    ->sendRequest("locales/{$locale}/file", $requestData, self::HTTP_METHOD_GET, true);
}