Datei hinzufügen

Add a new file to Crowdin project.

Anfrage

Note: Use the combination of project identifier, username, and account key to pass to this endpoint.

POST https://api.crowdin.com/api/project/{project-identifier}/add-file?login={username}&account-key={account-key}

Parameter

Name Wert Beschreibung
files benötigt Array Ein Array von Dateien, die zum Crowdin-Projekt hinzugefügt werden sollen. Array keys should contain file names with a path in Crowdin project.
Hinweis! Pro Dateiübertragung können nur maximal 20 Dateien gleichzeitig hochgeladen werden. Die maximale Dateigröße beträgt 100 MB.
titles optional Array An array of strings that defines titles for uploaded files. Array keys should contain file names with a path in Crowdin project.
export_patterns optional Array An array of strings that defines names of resulted files (translated files in the resulted archive). Array keys should contain file names with a path in Crowdin project.
type optional String Zulässige Werte sind:
  • 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” — generische JSON (*.json)
  • „xml” — generische XML (*.xml)
  • „ini” — generische INI (*.ini)
  • „rc” — Windows-Ressourcen (*.rc)
  • „resw” — Windows 8 Metro (*.resw)
  • „resjson” — Windows 8 Metro (*.resjson)
  • „qtts” — Nokia Qt (*.ts)
  • „joomla” — übersetzbare Ressourcen von Joomla (*.ini)
  • „chrome“ — Google Chrome-Erweiterungen (*.json)
  • „dtd” — Mozilla DTD (*.dtd)
  • „dklang“ — Delphi DKLang (*.dklang)
  • „flex” — Flex (*.properties)
  • „nsh“ — NSIS-Installer-Ressourcen (*.nsh)
  • „wxl” — WiX-Installer (*.wxl)
  • „xliff“ — XLIFF (*.xliff)
  • „html“ — HTML (*.html, *.htm, *.xhtml, *.xhtm)
  • „haml” — Haml (*.haml)
  • „txt” — einfacher Text (*.txt)
  • „csv“ — mit einem Komma getrennte Werte (*.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-Dokumente, Adobe InDesign Adobe FrameMaker(*.docx, *.dotx, *.odt, *.ott, *.xslx, *.xltx, *.pptx, *.potx, *.ods, *.ots, *.odg, *.otg, *.odp, *.otp, *.imdl, *.mif)
  • „sbv” — Youtube (*.sbv)
  • „vtt“ — Videountertitelung und WebVTT (*.vtt)
  • „srt” — SubRip (*.srt)
  • "i18next_json" — i18next JSON (*.json)
first_line_contains_header nur CSV- und XLS- bzw. XLSX-Dateien
optional
String Used when uploading CSV (or XLS/XLSX) files via API. Defines whether the first line should be imported or it contains the columns headers. Könnten keinen Wert enthalten.
import_translations CSV and XLS/XLSX multilingual files only
optional
integer Used when uploading CSV (or XLS/XLSX) files via API. Defines whether during the file import translations are imported as well – 1, or translations are not imported – 0. Standard: 1.
scheme CSV and XLS/XLSX files only
required
String 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 the 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 strings (if the imported file already contains translations).
  • "context" — Column contains some comments on source string. Kontext Informationen.
  • "max_length" — Column contains max. länge der Übersetzungen dieses Strings.
  • "labels" — Column contains labels.
  • "none" — Don't import this 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 optional String The name of the related version branch (Versions Management).
json optional String Könnten keinen Wert enthalten. Defines that response should be in the JSON format.
jsonp optional String Name der Rückruf Funktion. Defines that response should be in the JSONP format.
translate_content nur XML-Dateien
optional
Bool Defines whether to translate texts placed inside the tags. Zulässige Werte sind: „0” und „1”. Der Standardwert ist 1.
translate_attributes nur XML-Dateien
optional
Bool Defines whether to translate tags attributes. Zulässige Werte sind: „0” und „1”. Der Standardwert ist 1.
content_segmentation nur XML-Dateien
optional
Bool Defines whether to split long texts into smaller text segments. Zulässige Werte sind: „0” und „1”. Der Standardwert ist 1.
Important! This option disables the possibility to upload existing translations for XML files when enabled.
translatable_elements nur XML-Dateien
optional
Array This is an array of strings, where each item is the XPaths to DOM element that should be imported.
Acceptable values are:
  • /path/to/node
  • /path/to/attribute[@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 files only
optional
integer Defines whether single quote should be escaped by another single quote or backslash in exported translations. Zulässige Werte sind: „0”, „1”, „2” und „3”. Der Standardwert ist 3.

0 — Do not escape single quote;
1 — Escape single quote by another single quote;
2 — Escape single quote by backslash;
3 — Escape single quote by another single quote only in strings containing variables ( {0} )
Variablen
project-identifier String Projekt-ID.
login String Ihr Nutzername auf Crowdin.
account-key String Ihr Konto API-Schlüssel.

Antwort

If the method is successful it responds with an XML structure, as it is shown below.
<?xml version="1.0" encoding="UTF-8"?>
<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="UTF-8"?>
<error>
  <code>3</code>
  <message>API key is not valid</message>
</error>

Beispiele

curl \
  -F "files[/directory/arrays.xml]=@arrays.xml" \
  -F "files[strings.xml]=@strings.xml" \
  https://api.crowdin.com/api/project/{project-identifier}/add-file?login={username}&account-key={account-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?login={username}&account-key={account-key}
<?php
$post_params = array();
$request_url = 'https://api.crowdin.com/api/project/{project-identifier}/add-file?login={username}&account-key={account-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?login={username}&account-key={account-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;

War dieser Artikel hilfreich?