Aggiorna file

Upload the latest version of your source files (the ones, that should be localized) to your Crowdin project.

Richiesta

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}/update-file?login={username}&account-key={account-key}

Parametri

Nome Valore Descrizione
file obbligatori insieme Files array that should be updated.
Nota! 20 file massimo sono consentiti per caricare un trasferimento file di una volta.
titoli opzionale insieme An arrays of strings that defines titles for uploaded files. Array keys should contain file names with path in Crowdin project.
export_patterns opzionale insieme 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.
new_names optional insieme An arrays of strings that defines new names for previously imported files. Array keys should contain file names with path in Crowdin project.
solo file first_line_contains_header CSV and XLS/XLSX
opzionale
nella stringa Usato caricando i file CSV (o XLS/XLSX) tramite API. Defines whether first line should be imported or it contains columns headers. Potrebbe non contenere il valore.
schema solo file CSV e XLS/XLSX
richiesto
nella stringa Nota: Usato solo caricando il file CSV (o XLS/XLSX) per definire la mappatura delle colonne dei dati.
Valore accettabile è la combinazione delle seguenti costanti:
  • "identificatore" - La colonna contiene l'identificatore della stringa.
  • "source_phrase" — La colonna contiene solo la stringa sorgente (nella stringa del risultato conterrà la stessa stringa).
  • "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" — La colonna contiene dei commenti sulla stringa sorgente. Informazioni del contesto.
  • "max_length" — La colonna contiene la lunghezza massima di traduzione per questa stringa.
  • "none" — Do not import column.
Parametro di esempio che dovrai aggiungere: &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).
update_option optional nella stringa Depending on the value, "update_option" is used to preserve translations and preserve/remove validations of changed strings during file update. I valori sono:
  • "update_as_unapproved" — Preserve translations of changed strings and remove validations of those translations if they exist.
  • "update_without_changes" — Preserve translations and validations of changed strings.
Note: If it is not set translations for changed strings will be lost after file update. Utile per le correzioni di errori di ortografia e per modifiche minori nelle stringhe d'origine.
ramo opzionale nella stringa Il nome del ramo versione relativo (Versioni Gestione).
json opzionale nella stringa Potrebbe non contenere il valore. Definisce che la risposta dovrebbe essere in formato JSON.
jsonp opzionale nella stringa Nome della funzione di callback. Definisce che la risposta dovrebbe essere in formato JSONP.
escape_quotes properties files only
optional
intero Defines whether single quote should be escaped by another single quote or backslash in exported translations. Valori accettabili sono: 0, 1, 2, 3. Predefinito è 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} )
Variabili
identificatore-progetto nella stringa Identificatore progetto.
accesso nella stringa Il tuo nome utente su Crowdin.
chiave-profilo nella stringa La chiave API del tuo profilo.

Risposta

If successful, this method returns a XML structure, as it is shown below.
<?xml version="1.0" encoding="UTF-8"?>
<success>
</success>
Campione di risposta non riuscita:
<?xml version="1.0" encoding="UTF-8"?>
<error>
  <code>3</code>
  <message>Chiave API non valida</message>
</error>

Esempi

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

if (function_exists('curl_file_create')) {
$post_params['files[test.txt]'] = curl_file_create('/home/user/test.txt');
} else {
$post_params['files[test.txt]'] = '@/home/user/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}/update-file?login={username}&account-key={account-key}';

if (function_exists('curl_file_create')) {
$post_params['files[/directory/android.xml]'] = curl_file_create('/home/user/strings.xml');
} else {
$post_params['files[/directory/android.xml]'] = '@/home/user/strings.xml';
}

$post_params['new_names[/directory/android.xml]'] = 'strings.xml';

$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}/update-file?login={username}&account-key={account-key}';

if(function_exists('curl_file_create')) {
$post_params['files[directory/multilingual.csv]'] = curl_file_create('/home/user/example.csv');
} else {
$post_params['files[directory/multilingual.csv]'] = '@/home/user/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;

Questo articolo è stato utile?