Предварительный перевод

Pre-translate Crowdin project files.

Запрос

POST https://api.crowdin.com/api/project/{project-identifier}/pre-translate?key={project-key}

Параметры

Название Значение Описание
languages обязательный массив Set of languages to which pre-translation should be applied. For this use Сrowdin language codes.
files обязательный массив Files array that should be translated. Array keys should contain file names with path in Crowdin project.
method optional строка Defines which method will be used for pre-translation.
Допустимые значения:
  • "tm" — Pre-translation via Translation Memory
  • "mt" — Pre-translation via Machine Translation. Should be used with engine parameter.
Translation Memory is used by default.
engine optional строка Defines engine for Machine Translation.
Допустимые значения:
  • "microsoft" — Pre-translation via Microsoft Translator
  • "google" — Pre-translation via Google Translate
  • "yandex" — Pre-translation via Yandex.Translate
Note: Ensure that you have set appropriate keys for Machine Translation.
approve_translated optional булево Automatically approves translated strings. Acceptable values are: 1 or 0. It works only with TM pre-translation method.
auto_approve_option optional число Defines which translations added by pre-translation via TM should be auto-approved.
Acceptable values are 0, 1, or 2. The default value is 0.
  • "0" — all
  • "1" — with perfect match
  • "2" — all (skip auto-substituted suggestions)
Note:Works only when "approve_translated" parameter is used with value 1.
import_duplicates optional булево Adds translations even if the same translation already exists. Acceptable values are: 1 or 0. It works only with TM pre-translation method.
apply_untranslated_strings_only optional булево Applies translations for untranslated strings only. Acceptable values are: 1 or 0. It works only with TM pre-translation method.
perfect_match optional булево Pre-translate will be applied only for those strings, that have absolute match in source text and contextual information. Acceptable values are: 1 or 0. It works only with TM pre-translation method.
json необязательный строка Может не содержать значение. Указывает, что ответ должен быть в формате JSON.
jsonp необязательный строка Callback function name. Defines that response should be in JSONP format.
Переменные
project-identifier обязательный строка Должен содержать идентификатор проекта.
project-key обязательный строка API-ключ проекта.

Ответ

If the method is successful it responds with an XML structure, as it is shown below:
<?xml version="1.0" encoding="ISO-8859-1"?>
<success>
</success>
If you request languages that are not included in your project, the response looks like:
<?xml version="1.0" encoding="ISO-8859-1"?>
<success>
  <languages>
    <language status="skipped">French</language>
  </languages>
</success>
Unsuccessful response sample:
<?xml version="1.0" encoding="ISO-8859-1"?>
<error>
  <code>3</code>
  <message>API key is not valid</message>
</error>

Примеры

curl \
  -F "languages[]=fr" \
  -F "languages[]=uk" \
  -F "files[]=/example.txt" \
  https://api.crowdin.com/api/project/{project-identifier}/pre-translate?key={project-key}
<?php
$post_params = array();
$request_url = 'https://api.crowdin.com/api/project/{project-identifier}/pre-translate?key={project-key}';
$post_params['languages[]'] = 'uk';
$post_params['files[]'] = '/example.txt';

$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;