Загрузить перевод

Upload existing translations to your Crowdin project.

Запрос

Заметка: Either the project key or combination of имя пользователя и account key can be passed to this endpoint. Project identifier is passed in both cases.

POST https://api.crowdin.com/api/project/{идентификатор-проекта}/upload-translation?key={ключ-проекта}
POST https://api.crowdin.com/api/project/{project-identifier}/upload-translation?login={username}&account-key={account-key}

Параметры

Название Значение Описание
files обязательный массив Translated files array. Array keys should contain file names in Crowdin.
Note! 20 files max are allowed to upload per one time file transfer.
language обязательный строка Crowdin language code. With a single call it's possible to upload translations for several files but only into one of the languages.
import_duplicates optional булево Defines whether to add translation if there is the same translation previously added. Acceptable values are: 0 or 1. Default is 0.
import_eq_suggestions optional булево Defines whether to add translation if it is equal to source string at Crowdin. Acceptable values are: 0 or 1. Default is 0.
auto_approve_imported optional булево Mark uploaded translations as approved. Acceptable values are: 0 or 1. Default is 0.
format необязательный строка Specify this parameter if translations are uploaded to the project in XLIFF file format. Acceptable value is: xliff
To download XLIFF file for offline translation, apply the Export File method.
branch необязательный строка The name of related version branch (Versions Management).
json необязательный строка Может не содержать значение. Указывает, что ответ должен быть в формате JSON.
jsonp необязательный строка Callback function name. Defines that response should be in JSONP format.
Переменные
project-identifier обязательный строка Project identifier.
project-key optional строка Project API key. Either the project-key or combination of username and account-key are required.
username optional строка Your username in Crowdin. Either the project-key or combination of username and account-key are required.
account-key optional строка Your account API key. Either the project-key or combination of username and account-key are required.

Ответ

If successful, this method returns a XML structure, as it is shown below.
<?xml version="1.0" encoding="ISO-8859-1"?>
<success>
</success>
Образец ответа при неудавшемся запросе:
<?xml version="1.0" encoding="ISO-8859-1"?>
<error>
  <code>3</code>
  <message>API key is not valid</message>
</error>
The following request is partly successful because for all the file formats that do not have defined structure (such as: Generic XML, HTML, Plain Text, Markdown, OpenOffice, Microsoft Office, Adobe InDesign, Adobe FrameMaker, Webxml) the translations upload is not possible.
<?xml version="1.0" encoding="ISO-8859-1"?>
<success>
  <stats>
    <file name="spreadsheet.csv" status="uploaded"></file>
    <file name="webxml.xml" status="not_allowed"></file>
  </stats>
</success>

Примеры

curl \
  -F "files[strings.xml]=@strings.fr.xml" \
  -F "language=fr" \
  -F "auto_approve_imported=1" \
  https://api.crowdin.com/api/project/{идентификатор-проекта}/upload-translation?key={ключ-проекта}
<?php
$post_params = array();
$request_url = 'https://api.crowdin.com/api/project/{project-identifier}/upload-translation?key={project-key}';

if (function_exists('curl_file_create')) {
  $post_params['files[test.xml]'] = curl_file_create('/home/crowdin/test.fr.xml');
} else {
  $post_params['files[test.xml]'] = '@/home/crowdin/test.fr.xml';
}

$post_params['language'] = 'fr';
$post_params['import_eq_suggestions'] = 1;

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $request_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params);

$result = curl_exec($ch);
curl_close($ch);

echo $result;

Была ли эта статья полезной?