Добавить файл

Добавить новый файл в Crowdin проект.

Запрос

POST https://api.crowdin.com/api/project/{идентификатор-проекта}/add-file?key={ключ-проекта}

Параметры

Название Значение Описание
files обязательный массив Files array that should be added to Crowdin project. Array keys should contain file names with path in Crowdin project.
Note! 20 files max are allowed to upload per one time file transfer. The maximum size of one file is 100 MB.
titles необязательный массив An arrays of strings that defines titles for uploaded files. Array keys should contain file names with path in Crowdin project.
export_patterns необязательный массив An arrays of strings that defines names of resulted files (translated files in resulted archive). Array keys should contain file names with path in Crowdin project.
type необязательный строка Допустимые значения:
  • empty value or "auto" — Try to detect file type by extension or MIME type
  • "android" — Android (*.xml)
  • "macosx" — Mac OS X / iOS (*.strings)
  • "resx" — .NET, Windows Phone (*.resx)
  • "properties" — Java (*.properties)
  • "gettext" — GNU GetText (*.po, *.pot)
  • "yaml" — Ruby On Rails (*.yaml)
  • "php" — Hypertext Preprocessor (*.php)
  • "json" — Generic JSON (*.json)
  • "xml" — Generic XML (*.xml)
  • "ini" — Generic INI (*.ini)
  • "rc" — Windows Resources (*.rc)
  • "resw" — Windows 8 Metro (*.resw)
  • "resjson" — Windows 8 Metro (*.resjson)
  • "qtts" — Nokia Qt (*.ts)
  • "joomla" — Joomla localizable resources (*.ini)
  • "chrome" — Google Chrome Extension (*.json)
  • "dtd" — Mozilla DTD (*.dtd)
  • "dklang" — Delphi DKLang (*.dklang)
  • "flex" — Flex (*.properties)
  • "nsh" — NSIS Installer Resources (*.nsh)
  • "wxl" — WiX Installer (*.wxl)
  • "xliff" — XLIFF (*.xliff)
  • "html" — HTML (*.html, *.htm, *.xhtml, *.xhtm)
  • "haml" — Haml (*.haml)
  • "txt" — обычный текст (*.txt)
  • "csv" — Comma Separated Values (*.csv)
  • "md" — Markdown (*.md, *.text, *.markdown...)
  • "flsnp" — MadCap Flare (*.flnsp, .flpgpl .fltoc)
  • "fm_html" — Jekyll HTML (*.html)
  • "fm_md" — Jekyll Markdown (*.md)
  • "mediawiki" — MediaWiki (*.wiki, *.wikitext, *.mediawiki)
  • "docx" — Microsoft Office, OpenOffice.org Documents, Adobe InDesign Adobe FrameMaker(*.docx, *.dotx, *.odt, *.ott, *.xslx, *.xltx, *.pptx, *.potx, *.ods, *.ots, *.odg, *.otg, *.odp, *.otp, *.imdl, *.mif)
  • "sbv" — Youtube .sbv (*.sbv)
  • "vtt" — Video Subtitling and WebVTT (*.vtt)
  • "srt" — SubRip .srt (*.srt)
first_line_contains_header Только файлы CSV и XLS/XLSX
необязательный
строка Used when uploading CSV (or XLS/XLSX) files via API. Defines whether first line should be imported or it contains columns headers. May not contain value.
scheme Только файлы CSV и XLS/XLSX
обязательный
строка Note: Used only when uploading CSV (or XLS/XLSX) file to define data columns mapping.
Acceptable value is the combination of the following constants:
  • "identifier" — Column contains string identifier.
  • "source_phrase" — Column contains only source string (in result string will contain same string).
  • "source_or_translation" — Column contains source string but when exporting same column should contain translation (also when uploading existing translations, the value from this column will be used as a translated string).
  • "translation" — Column contains translated string (when imported file already contains translations).
  • "context" — Column contains some comments on source string. Context information.
  • "max_length" — Column contains max. length of translation for this string.
  • "none" — Do not import column.
Example parameter you will have to add: &scheme=identifier,source_or_translation

Note: for exported file to contain translations to all the target languages, specify language codes in scheme (e.g. &scheme=identifier,source_phrase,uk,ru,fr).
branch необязательный строка The name of related version branch (Versions Management).
json необязательный строка Может не содержать значение. Указывает, что ответ должен быть в формате JSON.
jsonp необязательный строка Callback function name. Defines that response should be in JSONP format.
translate_content Только XML файлы
необязательный
булево Defines whether to translate texts placed inside the tags. Acceptable values are: 0 or 1. Default is 1.
translate_attributes Только XML файлы
необязательный
булево Defines whether to translate tags attributes. Acceptable values are: 0 or 1. Default is 1.
content_segmentation Только XML файлы
необязательный
булево Defines whether to split long texts into smaller text segments. Допустимые значения: 0 или 1. Значение по умолчанию — 1.
Important! This option disables the possibility to upload existing translations for XML files when enabled.
translatable_elements Только XML файлы
необязательный
массив This is an array of strings, where each item is the XPaths to DOM element that should be imported.
Допустимые значения:
  • /путь/к/ноде
  • /путь/к/атрибуту[@attr]
  • //node , node - import each node named "node"
  • //[@attr] - import сontent of each attribute named "attr"
  • nodeone/nodetwo - import all "nodetwo" nodes (root node is not required to be specified)
  • /nodeone//nodetwo - import all "nodetwo" nodes ignoring other nodes between "nodeone" and "nodetwo"
  • //node[@attr] - import content of attributes "attr" stored in nodes named "node"

Note! If defined, the parameters "translate_content" and "translate_attributes" are not taken into account while importing.
escape_quotes Только файлы .properties
необязательный
целое Defines whether single quote should be escaped by another single quote or backslash in exported translations. Допустимые значения: 0, 1, 2, 3. Значение по умолчанию — 3.

0 — Не экранировать одинарные кавычки;
1 — Экранировать одинарные кавычки другими одинарными кавычками;
2 — Экранировать одинарные кавычки бэкслешем (\);
3 — Экранировать одинарные кавычки другими одинарными кавычками только в строках, содержащих переменные ( {0} )
Переменные
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>
  <stats>
    <file file_id="342">
      <name>strings.xml</name>
      <strings>4</strings>
      <words>11</words>
    </file>
  </stats>
</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 "files[/directory/arrays.xml]=@arrays.xml" \
  -F "files[strings.xml]=@strings.xml" \
  https://api.crowdin.com/api/project/{project-identifier}/add-file?key={project-key}
curl \
  -F "files[directory/multilingual.csv]=@example.csv" \
  -F "export_patterns[directory/multilingual.csv]=/%locale%/%original_file_name%" \
  -F "titles[directory/multilingual.csv]=Title in Crowdin Project" \
  -F "scheme=identifier,source_phrase,translation" \
  -F "first_line_contains_header=true" \
  https://api.crowdin.com/api/project/{project-identifier}/add-file?key={project-key}
<?php
$post_params = array();
$request_url = 'https://api.crowdin.com/api/project/{project-identifier}/add-file?key={project-key}';

if (function_exists('curl_file_create')) {
  $post_params['files[test.txt]'] = curl_file_create('/home/crowdin/test.txt');
} else {
  $post_params['files[test.txt]'] = '@/home/crowdin/test.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;
<?php
$post_params = array();
$request_url = 'https://api.crowdin.com/api/project/{project-identifier}/add-file?key={project-key}';

if(function_exists('curl_file_create')) {
  $post_params['files[directory/multilingual.csv]'] = curl_file_create('/home/crowdin/example.csv');
} else {
  $post_params['files[directory/multilingual.csv]'] = '@/home/crowdin/example.csv';
}

$post_params['export_patterns[directory/multilingual.csv]'] = '/translations/%original_file_name%';
$post_params['titles[directory/multilingual.csv]'] = 'Title in Crowdin Project';
$post_params['scheme'] = 'identifier,source_phrase,translation';
$post_params['first_line_contains_header'] = '';

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