Quelldateien über die API hochladen und verwalten
Verwenden Sie diese API, um neue Quelldateien hochzuladen, veraltete zu ersetzen, den Fortschritt der Übersetzung zu verfolgen und abgeschlossene Übersetzungen herunterzuladen.
Unabhängig davon, ob Sie eine einzelne Datei verwalten oder einen Workflow der kontinuierlichen Lokalisierung automatisieren, gibt Ihnen diese API die volle Kontrolle über die Inhalte, die Sie zur Übersetzung senden, und darüber, wie Sie die Übersetzungen erhalten.
API-Schnelllinks
Wie die PTC-API Quelldateien identifiziert und organisiert
Die PTC-API verwendet ein flexibles System, das auf Datei-Tags und Dateipfaden basiert. Diese Parameter arbeiten zusammen, um sicherzustellen, dass jede Datei, die Sie hochladen, aktualisieren oder anfordern, klar definiert und einfach zu verwalten ist.
Datei-Tags
Datei-Tags sind eine flexible Möglichkeit, Quelldateien in Übersetzungsprojekten zu gruppieren und zu organisieren. Sie können sie wie Kategorien verwenden, um sie an Ihre Workflow-Anforderungen anzupassen. Zum Beispiel können Datei-Tags Folgendes anzeigen:
- Versionskontrolle:
v1.0,beta,production - Feature-Branches:
user-auth,dashboard-redesign - Anwendungskontext:
mobile-app,admin-panel,marketing - Team-Zuständigkeit:
frontend-team,content-team - Workflow-Status:
approved,pending-review,priority-high
Namen von Datei-Tags sind in den meisten API-Operationen optional. Jedoch hat jede Quelldatei immer mindestens ein Tag. Ein Standard-Datei-Tag wird bei der Projekteinrichtung automatisch erstellt und zugewiesen. Dieses Standardverhalten hält Projekte auch bei einfachen Konfigurationen organisiert und ermöglicht es Ihnen gleichzeitig, bei Bedarf erweiterte Tagging-Strukturen aufzubauen.
Name des Datei-Tags + Dateipfad
Jede Quelldatei wird durch die Kombination aus dem Namen des Datei-Tags und dem Dateipfad eindeutig identifiziert.
- Wenn Sie beim Hochladen oder Verarbeiten einer Datei kein benutzerdefiniertes Datei-Tag angeben, wird das Standard-Tag automatisch zugewiesen.
- Der Tag-Name + Pfad einer Datei definieren zusammen ihre Identität. Diese Kombination stellt sicher, dass jede Datei innerhalb Ihres Projekts eindeutig ist, selbst wenn verschiedene Versionen oder Kontexte denselben Dateipfad teilen.
Abfrageparameter
Beim Abrufen einer bestimmten Datei können zugehörige Endpunkte Abfrageparameter akzeptieren, wie zum Beispiel:
file_tag_name– Das mit der Datei verknüpfte Tagfile_path– Der Pfad zur Datei
Diese Parameter ermöglichen es Ihnen, die richtigen Dateien aus Ihrem Projekt präzise zu lokalisieren und abzurufen.
Alle Quelldateien im Projekt auflisten
Listet alle Quelldateien in Ihrem Projekt auf, mit Optionen zum Filtern, Sortieren und Paginieren der Ergebnisse. Dies ist nützlich, wenn Sie Ihre Dateien durchsuchen, ihren Status überprüfen oder bestimmte Dateien basierend auf Tag, Pfad oder Upload-Methode finden möchten.
HTTP-Anfrage
GET https://app.ptc.wpml.org/api/v1/source_filesParameter
| Parameter | Typ | Erforderlich | Standardwert | Beschreibung |
|---|---|---|---|---|
page |
integer | Nein | 1 |
Die Seitenzahl für die Paginierung. Muss größer als 0 sein. |
per_page |
integer | Nein | 50 |
Die Anzahl der Elemente pro Seite. Muss größer als 0 sein. |
order_by |
string | Nein | created_at |
Das Feld, nach dem sortiert werden soll. Zulässige Werte: id, created_at, updated_at. |
sort |
string | Nein | desc |
Die Sortierrichtung. Zulässige Werte: asc, desc. |
file_path |
string | Nein | – | Filtert nach dem genauen Dateipfad. |
upload_origin |
string | Nein | – | Filtert danach, wie die Datei hochgeladen wurde. Zu den zulässigen Werten gehören: git, manual, api. |
Antworten
Erfolgsantwort
{
"source_files": [
{
"id": 123,
"file_path": "locales/en.po",
"translation_path": "locales/{{lang}}.po",
"additional_translation_files": ["locales/{{lang}}.mo"],
"status": "completed",
"upload_origin": "git",
"created_at": "2024-01-15T10:30:00.000Z",
"updated_at": "2024-01-15T14:20:00.000Z",
"file_tag": {
"id": 456,
"name": "frontend"
},
"download_url": "https://app.ptc.wpml.org/api/v1/source_files/download_translations?file_path=locales/en.po&file_tag_name=frontend"
}
],
"pagination": {
"page": 1,
"per_page": 50,
"total": 150,
"total_pages": 3,
"has_next_page": true,
"has_previous_page": false
}
}Antwortschema
Quelldatei-Objekt:
| Feld | Typ | Beschreibung |
|---|---|---|
id |
integer | Die eindeutige Kennung der Quelldatei. |
file_path |
string | Der Pfad zur Quelldatei innerhalb des Projekts. |
translation_path |
string | Das Muster dafür, wo übersetzte Dateien gespeichert werden sollen. |
additional_translation_files |
array[string] | Die Pfade für eventuelle zusätzliche Ausgabedateien. |
status |
string | Der aktuelle Verarbeitungsstatus der Quelldatei. |
upload_origin |
string | Wie die Datei hochgeladen wurde (git, manual, api). |
created_at |
string | Ein ISO-8601-Zeitstempel, der angibt, wann die Quelldatei ursprünglich erstellt wurde. |
updated_at |
string | Ein ISO-8601-Zeitstempel, der angibt, wann die Quelldatei zuletzt aktualisiert wurde. |
file_tag |
object | Informationen über das Datei-Tag. |
file_tag.id |
integer | Die Kennung des Datei-Tags. |
file_tag.name |
string | Der Name des Datei-Tags. |
download_url |
string | Die URL zum Herunterladen von Übersetzungen für diese Quelldatei. |
Paginierungs-Objekt:
| Feld | Typ | Beschreibung |
|---|---|---|
page |
integer | Die aktuelle Seitenzahl. |
per_page |
integer | Die Anzahl der Elemente pro Seite. |
total |
integer | Die Gesamtzahl der Quelldateien. |
total_pages |
integer | Die Gesamtzahl der Seiten. |
has_next_page |
boolean | Gibt an, ob eine nächste Seite verfügbar ist. |
has_previous_page |
boolean | Gibt an, ob eine vorherige Seite verfügbar ist. |
Fehlerantworten
Nicht autorisiert
{
"error": "Unauthorized access. Please provide a valid API token."
}Zugriff verweigert
{
"error": "Access denied. Insufficient permissions."
}Ungültige Parameter
{
"error": "Invalid parameters provided."
}Beispielanfragen
Einfache Anfrage:
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json"Gefilterte Anfrage:
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files?file_tag_name=frontend&page=1&per_page=25&order_by=updated_at&sort=desc" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json"Code-Beispiele
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files?file_tag_name=frontend&page=1&per_page=25" \
-H "Authorization: Bearer YOUR_API_TOKEN"require 'net/http'
require 'uri'
uri = URI('https://app.ptc.wpml.org/api/v1/source_files')
uri.query = URI.encode_www_form(file_tag_name: 'frontend', page: 1, per_page: 25)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer YOUR_API_TOKEN'
response = http.request(request)
puts response.bodyimport requests
headers = {
'Authorization': 'Bearer YOUR_API_TOKEN'
}
params = {
'file_tag_name': 'frontend',
'page': 1,
'per_page': 25
}
response = requests.get('https://app.ptc.wpml.org/api/v1/source_files',
headers=headers, params=params)
print(response.json())<?php
$params = http_build_query([
'file_tag_name' => 'frontend',
'page' => 1,
'per_page' => 25
]);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.ptc.wpml.org/api/v1/source_files?{$params}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_TOKEN'
],
]);
$response = curl_exec($curl);
curl_close($curl);
print_r(json_decode($response, true));
?>import okhttp3.*;
OkHttpClient client = new OkHttpClient();
HttpUrl url = HttpUrl.parse("https://app.ptc.wpml.org/api/v1/source_files")
.newBuilder()
.addQueryParameter("file_tag_name", "frontend")
.addQueryParameter("page", "1")
.addQueryParameter("per_page", "25")
.build();
Request request = new Request.Builder()
.url(url)
.addHeader("Authorization", "Bearer YOUR_API_TOKEN")
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://app.ptc.wpml.org/api/v1/source_files", nil)
q := req.URL.Query()
q.Add("file_tag_name", "frontend")
q.Add("page", "1")
q.Add("per_page", "25")
req.URL.RawQuery = q.Encode()
req.Header.Add("Authorization", "Bearer YOUR_API_TOKEN")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_TOKEN");
var response = await client.GetAsync("https://app.ptc.wpml.org/api/v1/source_files?file_tag_name=frontend&page=1&per_page=25");
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);const axios = require('axios');
const response = await axios.get('https://app.ptc.wpml.org/api/v1/source_files', {
headers: { 'Authorization': 'Bearer YOUR_API_TOKEN' },
params: {
file_tag_name: 'frontend',
page: 1,
per_page: 25
}
});
console.log(response.data);Übersetzungsstrings abrufen
Ruft alle übersetzbaren Strings aus einer bestimmten Quelldatei ab, zusammen mit ihren vorhandenen Übersetzungen in allen Zielsprachen.
Dieser Endpunkt ist nützlich, um Inhalte abzurufen, die übersetzt werden müssen oder bereits übersetzt wurden. Die Quelldatei wird durch file_path und file_tag_name identifiziert.
HTTP-Anfrage
GET https://app.ptc.wpml.org/api/v1/source_files/translation_stringsParameter
| Parameter | Typ | Erforderlich | Standardwert | Beschreibung |
|---|---|---|---|---|
file_path |
string | Ja | – | Der Pfad zur Quelldatei innerhalb des Projekts. |
file_tag_name |
string | Nein | – | Der Name des Datei-Tags. Wenn nicht angegeben, wird das Standard-Tag des Projekts verwendet. |
page |
integer | Nein | 1 |
Die Seitenzahl für die Paginierung (wird als Cursor verwendet). Muss größer als 0 sein. |
q |
string | Nein | – | Die Suchanfrage, um Übersetzungsstrings nach ihrem Ausgangstext zu filtern. |
Antworten
Erfolgsantwort
{
"total_strings_count": 1250,
"translation_strings": [
{
"source": "Welcome to our application",
"translations": {
"es": "Bienvenido a nuestra aplicación",
"fr": "Bienvenue dans notre application",
"de": "Willkommen in unserer Anwendung"
}
},
{
"source": "Login",
"translations": {
"es": "Iniciar sesión",
"fr": "Connexion",
"de": "Anmelden"
}
}
],
"cursor": 1
}Antwort-Schema
| Feld | Typ | Beschreibung |
|---|---|---|
total_strings_count |
integer | Die Gesamtzahl der übersetzbaren Strings in der Quelldatei. |
translation_strings |
array[object] | Das Array der Übersetzungsstring-Objekte (paginiert, max. 500 pro Seite). |
translation_strings[].source |
string | Der zu übersetzende Original-Ausgangstext. |
translation_strings[].translations |
object | Ein Hash von Übersetzungen, bei dem die Keys die ISO-Sprachcodes und die Werte die übersetzten Texte sind. |
cursor |
integer | Der aktuelle Seiten-Cursor, der für die Paginierung verwendet wird. |
Fehlerantworten
Quelldatei nicht gefunden
{
"error": "Source file not found"
}Nicht autorisiert
{
"error": "Unauthorized access. Please provide a valid API token."
}Zugriff verweigert
{
"error": "Access denied. Insufficient permissions."
}Ungültige Parameter
{
"error": "Invalid parameters provided."
}Beispielanfragen
Einfache Anfrage:
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files/translation_strings?file_path=locales/en.po" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json"Eine Anfrage mit Datei-Tag:
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files/translation_strings?file_path=locales/en.po&file_tag_name=frontend" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json"Eine Anfrage mit Paginierung und Suche:
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files/translation_strings?file_path=locales/en.po&file_tag_name=frontend&page=2&q=welcome" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json"Codebeispiele
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files/translation_strings?file_path=locales/en.po&file_tag_name=frontend&page=1&q=login" \
-H "Authorization: Bearer YOUR_API_TOKEN"require 'net/http'
require 'uri'
uri = URI('https://app.ptc.wpml.org/api/v1/source_files/translation_strings')
uri.query = URI.encode_www_form(file_path: 'locales/en.po', file_tag_name: 'frontend', page: 1, q: 'login')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer YOUR_API_TOKEN'
response = http.request(request)
puts response.bodyimport requests
headers = {
'Authorization': 'Bearer YOUR_API_TOKEN'
}
params = {
'file_path': 'locales/en.po',
'file_tag_name': 'frontend',
'page': 1,
'q': 'login'
}
response = requests.get('https://app.ptc.wpml.org/api/v1/source_files/translation_strings',
headers=headers, params=params)
print(response.json())<?php
$params = http_build_query([
'file_path' => 'locales/en.po',
'file_tag_name' => 'frontend',
'page' => 1,
'q' => 'login'
]);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.ptc.wpml.org/api/v1/source_files/translation_strings?{$params}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_TOKEN'
],
]);
$response = curl_exec($curl);
curl_close($curl);
print_r(json_decode($response, true));
?>import okhttp3.*;
OkHttpClient client = new OkHttpClient();
HttpUrl url = HttpUrl.parse("https://app.ptc.wpml.org/api/v1/source_files/translation_strings")
.newBuilder()
.addQueryParameter("file_path", "locales/en.po")
.addQueryParameter("file_tag_name", "frontend")
.addQueryParameter("page", "1")
.addQueryParameter("q", "login")
.build();
Request request = new Request.Builder()
.url(url)
.addHeader("Authorization", "Bearer YOUR_API_TOKEN")
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://app.ptc.wpml.org/api/v1/source_files/translation_strings", nil)
q := req.URL.Query()
q.Add("file_path", "locales/en.po")
q.Add("file_tag_name", "frontend")
q.Add("page", "1")
q.Add("q", "login")
req.URL.RawQuery = q.Encode()
req.Header.Add("Authorization", "Bearer YOUR_API_TOKEN")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_TOKEN");
var response = await client.GetAsync("https://app.ptc.wpml.org/api/v1/source_files/translation_strings?file_path=locales/en.po&file_tag_name=frontend&page=1&q=login");
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);const axios = require('axios');
const response = await axios.get('https://app.ptc.wpml.org/api/v1/source_files/translation_strings', {
headers: { 'Authorization': 'Bearer YOUR_API_TOKEN' },
params: {
file_path: 'locales/en.po',
file_tag_name: 'frontend',
page: 1,
q: 'login'
}
});
console.log(response.data);Quelldatei erstellen
Registriert eine neue Quelldatei in Ihrem Projekt, sodass sie übersetzungsbereit ist.
Dieser Endpunkt erstellt den Dateieintrag und richtet dessen Übersetzungskonfiguration ein, fügt den eigentlichen Dateiinhalt jedoch nicht hinzu.
Nach dem Erstellen der Datei müssen Sie den Endpunkt Quelldatei verarbeiten verwenden, um den Inhalt hochzuladen und den Übersetzungsprozess zu starten.
HTTP-Anfrage
POST https://app.ptc.wpml.org/api/v1/source_filesParameter
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
file_path |
string | Ja | Der Pfad, unter dem die Quelldatei im Projekt gespeichert werden soll. Muss eine unterstützte Dateiendung haben. |
output_file_path |
string | Ja | Das Ausgabepfad-Muster für übersetzte Dateien. Verwenden Sie {{lang}} als Platzhalter für den Sprachcode. |
file_tag_name |
string | Nein | Der Name des Datei-Tags, unter dem die Quelldatei registriert werden soll. Wenn nicht angegeben, wird das Standard-Datei-Tag des Projekts verwendet. |
translations |
array[object] | Nein | Die bereits vorhandenen Übersetzungsdateien, die zusammen mit der Quelldatei hochgeladen werden sollen. Diese Dateien werden wie bereitgestellt gespeichert, und ihre Strings werden von der PTC nicht neu übersetzt. Beachten Sie, dass die Bereitstellung bereits vorhandener Übersetzungen nicht empfohlen wird, da die PTC bessere Ergebnisse liefert, wenn sie den vollständigen Kontext Ihres Projekts nutzen und von Grund auf übersetzen kann. |
translations[].target_language_iso |
string | Ja | Der ISO-Code der Zielsprache für diese Übersetzung. Die vollständige Liste der unterstützten Sprachen und ihrer ISO-Codes finden Sie im Endpunkt Alle Zielsprachen auflisten. |
translations[].file |
file | Ja | Die hochzuladende Übersetzungsdatei. |
additional_translation_files |
array[object] | Nein | Konfigurationen für zusätzliche Ausgabedateien für bestimmte Formate. Weitere Informationen dazu, welche Formate zusätzliche Ausgabedateien unterstützen, finden Sie im Endpunkt Unterstützte Dateiformate auflisten. Bei nicht unterstützten Formaten wird dieses Feld ignoriert. |
additional_translation_files[].type |
string | Ja | Siehe unterstützte Dateiformate für weitere Details. |
additional_translation_files[].path |
string | Ja | Das Pfadmuster für die Datei. |
Antworten
Erfolgsantwort
{
"source_file": {
"id": 123,
"file_path": "src/locales/en.json",
"created_at": "2024-01-15T10:30:00.000Z",
"file_tag": {
"id": 456,
"name": "frontend"
}
}
}Antwort-Schema
| Feld | Typ | Beschreibung |
|---|---|---|
source_file.id |
integer | Die eindeutige Kennung für die erstellte Quelldatei. |
source_file.file_path |
string | Der Pfad der Quelldatei innerhalb des Projekts. |
source_file.created_at |
string | Ein ISO-8601-Zeitstempel, der angibt, wann die Quelldatei ursprünglich erstellt wurde. |
source_file.file_tag.id |
integer | Die Kennung des Datei-Tags. |
source_file.file_tag.name |
string | Der Name des Datei-Tags. |
Fehlerantworten
Validierung fehlgeschlagen
{
"success": false,
"error": "Source file creation failed"
}Nicht autorisiert
{
"error": "Unauthorized access. Please provide a valid API token."
}Zugriff verweigert
{
"error": "Access denied. Insufficient permissions."
}Beispielanfragen
Einfache Erstellung einer Quelldatei:
curl -X POST "https://app.ptc.wpml.org/api/v1/source_files" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "file_path=src/locales/en.json" \
-F "output_file_path=src/locales/{{lang}}.json" \
-F "file_tag_name=frontend"Der Create-Aufruf akzeptiert kein callback_url. Das Registrieren einer Quelldatei startet keine Übersetzung, daher gibt es für einen Callback nichts anzukündigen – übergeben Sie diese URL stattdessen an Quelldatei verarbeiten oder an Quelldateien im Stapel hochladen, da dies die Aufrufe sind, mit denen die Arbeit beginnt.
Anfrage mit bereits vorhandenen Übersetzungen:
curl -X POST "https://app.ptc.wpml.org/api/v1/source_files" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "file_path=src/messages.json" \
-F "output_file_path=locales/{{lang}}/messages.json" \
-F "translations[0][target_language_iso]=es" \
-F "translations[0][file]=@spanish_translations.json" \
-F "translations[1][target_language_iso]=fr" \
-F "translations[1][file]=@french_translations.json"Anfrage mit zusätzlichen Ausgabedateien:
curl -X POST "https://app.ptc.wpml.org/api/v1/source_files" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "file_path=src/messages.po" \
-F "output_file_path=locales/{{lang}}/messages.po" \
-F "additional_translation_files[][type]=mo" \
-F "additional_translation_files[][path]=locales/{{lang}}/messages.mo" \
-F "additional_translation_files[][type]=json" \
-F "additional_translation_files[][path]=locales/{{lang}}/messages.json"Codebeispiele
- JavaScript (FormData)
- Python (requests)
- PHP (cURL)
- Node.js (axios)
- Callback-Request-Body
curl -X POST "https://app.ptc.wpml.org/api/v1/source_files" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "file_path=src/locales/en.json" \
-F "output_file_path=src/locales/{{lang}}.json"require 'net/http'
require 'uri'
uri = URI('https://app.ptc.wpml.org/api/v1/source_files')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer YOUR_API_TOKEN'
request.set_form_data(
'file_path' => 'src/locales/en.json',
'output_file_path' => 'src/locales/{{lang}}.json'
)
response = http.request(request)
puts response.bodyimport requests
headers = {'Authorization': 'Bearer YOUR_API_TOKEN'}
data = {
'file_path': 'src/locales/en.json',
'output_file_path': 'src/locales/{{lang}}.json'
}
response = requests.post('https://app.ptc.wpml.org/api/v1/source_files', headers=headers, data=data)
print(response.json())<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://app.ptc.wpml.org/api/v1/source_files',
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query([
'file_path' => 'src/locales/en.json',
'output_file_path' => 'src/locales/{{lang}}.json'
]),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_TOKEN'
],
]);
$response = curl_exec($curl);
curl_close($curl);
print_r(json_decode($response, true));
?>import okhttp3.*;
OkHttpClient client = new OkHttpClient();
RequestBody body = new FormBody.Builder()
.add("file_path", "src/locales/en.json")
.add("output_file_path", "src/locales/{{lang}}.json")
.build();
Request request = new Request.Builder()
.url("https://app.ptc.wpml.org/api/v1/source_files")
.addHeader("Authorization", "Bearer YOUR_API_TOKEN")
.post(body)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());package main
import (
"fmt"
"io"
"net/http"
"net/url"
"strings"
)
func main() {
form := url.Values{}
form.Set("file_path", "src/locales/en.json")
form.Set("output_file_path", "src/locales/{{lang}}.json")
req, _ := http.NewRequest("POST", "https://app.ptc.wpml.org/api/v1/source_files", strings.NewReader(form.Encode()))
req.Header.Add("Authorization", "Bearer YOUR_API_TOKEN")
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_TOKEN");
var form = new FormUrlEncodedContent(new Dictionary<string, string>
{
{ "file_path", "src/locales/en.json" },
{ "output_file_path", "src/locales/{{lang}}.json" }
});
var response = await client.PostAsync("https://app.ptc.wpml.org/api/v1/source_files", form);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);const axios = require('axios');
const params = new URLSearchParams();
params.append('file_path', 'src/locales/en.json');
params.append('output_file_path', 'src/locales/{{lang}}.json');
const response = await axios.post('https://app.ptc.wpml.org/api/v1/source_files', params, {
headers: { 'Authorization': 'Bearer YOUR_API_TOKEN' }
});
console.log(response.data);{
"source_file_id": 123,
"status": "completed",
"file_tag_name": "frontend",
"download_url": "https://app.ptc.wpml.org/api/v1/source_files/download_translations?file_path=src/locales/en.json&file_tag_name=frontend",
"file_path": "src/locales/en.json"
}Quelldatei verarbeiten
Lädt Inhalte in eine bestehende Quelldatei hoch und startet den Übersetzungsprozess.
Dieser Endpunkt ersetzt den aktuellen Inhalt der Datei, aktualisiert die gespeicherten übersetzbaren Strings und startet die automatische Übersetzung.
Um diesen Endpunkt zu verwenden, muss die Quelldatei bereits im Projekt existieren. Wenn Sie diese noch nicht erstellt haben, siehe Quelldatei erstellen.
HTTP-Anfrage
PUT https://app.ptc.wpml.org/api/v1/source_files/processParameter
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
file |
file | Ja | Die hochzuladende Quelldatei. Der Dateiinhalt wird validiert, um sicherzustellen, dass er mit der deklarierten Dateiendung übereinstimmt. Wenn die Dateiendung beispielsweise .json lautet, muss der hochgeladene Inhalt gültiges JSON sein. |
file_path |
string | Ja | Der Pfad zur bestehenden Quelldatei im Projekt, die aktualisiert werden soll. |
file_tag_name |
string | Nein | Der Name des Datei-Tags, das mit der Quelldatei verknüpft ist. Falls nicht angegeben, wird das Standard-Datei-Tag des Projekts verwendet. |
callback_url |
string | Nein | Die URL, die Webhook-Benachrichtigungen empfängt, wenn die Dateiverarbeitung abgeschlossen ist. |
Antworten
Erfolgsantwort
{
"source_file": {
"id": 123,
"file_path": "src/locales/en.json",
"created_at": "2024-01-15T10:30:00.000Z",
"file_tag": {
"id": 456,
"name": "frontend"
}
}
}Antwortschema
| Feld | Typ | Beschreibung |
|---|---|---|
source_file.id |
integer | Der eindeutige Bezeichner für die verarbeitete Quelldatei. |
source_file.file_path |
string | Der Pfad der Quelldatei innerhalb des Projekts. |
source_file.created_at |
string | Ein ISO-8601-Zeitstempel, der angibt, wann die Quelldatei ursprünglich erstellt wurde. |
source_file.file_tag.id |
integer | Der Bezeichner des Datei-Tags. |
source_file.file_tag.name |
string | Der Name des Datei-Tags. |
Fehlerantworten
Nicht unterstütztes oder ungültiges Dateiformat
Der Process-Aufruf ersetzt den Dateiinhalt durch Ihren Upload, es gibt also keinen Suchvorgang, der fehlschlagen könnte – dieser Endpunkt kennt keinen Not-Found-Fall. Die einzige Ablehnung, die er zurückgibt, betrifft die Inhaltsprüfung der hochgeladenen Datei.
{
"success": false,
"message": "Unprocessable Entity",
"code": 422,
"errors": [9001]
}errors ist ein Array aus numerischen Codes, kein Objekt mit Feldschlüsseln. 9001 bedeutet, dass der Inhalt nicht als das Format geparst werden konnte, das seine Dateiendung angibt. Einige Ablehnungen fügen zusätzlich ein additional_info-Objekt mit den genauen Details hinzu.
Nicht autorisiert
{
"error": "Unauthorized access. Please provide a valid API token."
}Verboten
{
"error": "Access denied. Insufficient permissions."
}Workflow
- Voraussetzung: Die Quelldatei muss bereits über Quelldatei erstellen erstellt worden sein.
- Datei-Upload: Neuer Inhalt wird hochgeladen und ersetzt den bestehenden Dateiinhalt.
- Verarbeitung: Die neuen übersetzbaren Strings werden extrahiert und automatisch übersetzt.
- Callback: Eine optionale Webhook-Benachrichtigung wird gesendet, wenn die Verarbeitung abgeschlossen ist.
Webhook-Callback
Wenn eine callback_url angegeben ist, sendet die PTC eine POST-Anfrage an diese URL, sobald die Verarbeitung abgeschlossen ist.
Body der Callback-Anfrage:
{
"source_file_id": 123,
"status": "completed",
"file_tag_name": "frontend",
"download_url": "https://app.ptc.wpml.org/api/v1/source_files/download_translations?file_path=src/locales/en.json&file_tag_name=frontend",
"file_path": "src/locales/en.json"
}Beispielanfragen
Einfache Dateiverarbeitung:
curl -X PUT "https://app.ptc.wpml.org/api/v1/source_files/process" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "file=@updated_translations.json" \
-F "file_path=src/locales/en.json" \
-F "file_tag_name=frontend"Anfrage mit Callback-URL:
curl -X PUT "https://app.ptc.wpml.org/api/v1/source_files/process" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "file=@messages.po" \
-F "file_path=locales/messages.po" \
-F "callback_url=https://your-app.com/webhooks/translation-complete"Codebeispiele
curl -X PUT "https://app.ptc.wpml.org/api/v1/source_files/process" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "file=@updated_translations.json" \
-F "file_path=src/locales/en.json" \
-F "file_tag_name=frontend" \
-F "callback_url=https://your-app.com/webhooks/complete"require 'net/http'
require 'uri'
uri = URI('https://app.ptc.wpml.org/api/v1/source_files/process')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Put.new(uri)
request['Authorization'] = 'Bearer YOUR_API_TOKEN'
request.set_form(
[
['file', File.open('updated_translations.json')],
['file_path', 'src/locales/en.json'],
['file_tag_name', 'frontend'],
['callback_url', 'https://your-app.com/webhooks/complete']
],
'multipart/form-data'
)
response = http.request(request)
puts response.bodyimport requests
headers = {'Authorization': 'Bearer YOUR_API_TOKEN'}
files = {'file': open('updated_translations.json', 'rb')}
data = {
'file_path': 'src/locales/en.json',
'file_tag_name': 'frontend',
'callback_url': 'https://your-app.com/webhooks/complete'
}
response = requests.put('https://app.ptc.wpml.org/api/v1/source_files/process',
headers=headers, files=files, data=data)
print(response.json())<?php
$post_data = [
'file' => new CURLFile('updated_translations.json'),
'file_path' => 'src/locales/en.json',
'file_tag_name' => 'frontend',
'callback_url' => 'https://your-app.com/webhooks/complete'
];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://app.ptc.wpml.org/api/v1/source_files/process',
CURLOPT_CUSTOMREQUEST => 'PUT',
CURLOPT_POSTFIELDS => $post_data,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_TOKEN'
],
]);
$response = curl_exec($curl);
curl_close($curl);
print_r(json_decode($response, true));
?>import okhttp3.*;
import java.io.File;
OkHttpClient client = new OkHttpClient();
MultipartBody body = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("file", "updated_translations.json",
RequestBody.create(new File("updated_translations.json"), MediaType.parse("application/octet-stream")))
.addFormDataPart("file_path", "src/locales/en.json")
.addFormDataPart("file_tag_name", "frontend")
.addFormDataPart("callback_url", "https://your-app.com/webhooks/complete")
.build();
Request request = new Request.Builder()
.url("https://app.ptc.wpml.org/api/v1/source_files/process")
.addHeader("Authorization", "Bearer YOUR_API_TOKEN")
.put(body)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
var buf bytes.Buffer
w := multipart.NewWriter(&buf)
file, _ := os.Open("updated_translations.json")
defer file.Close()
fw, _ := w.CreateFormFile("file", "updated_translations.json")
io.Copy(fw, file)
w.WriteField("file_path", "src/locales/en.json")
w.WriteField("file_tag_name", "frontend")
w.WriteField("callback_url", "https://your-app.com/webhooks/complete")
w.Close()
req, _ := http.NewRequest("PUT", "https://app.ptc.wpml.org/api/v1/source_files/process", &buf)
req.Header.Add("Authorization", "Bearer YOUR_API_TOKEN")
req.Header.Add("Content-Type", w.FormDataContentType())
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_TOKEN");
var form = new MultipartFormDataContent();
form.Add(new StreamContent(File.OpenRead("updated_translations.json")), "file", "updated_translations.json");
form.Add(new StringContent("src/locales/en.json"), "file_path");
form.Add(new StringContent("frontend"), "file_tag_name");
form.Add(new StringContent("https://your-app.com/webhooks/complete"), "callback_url");
var response = await client.PutAsync("https://app.ptc.wpml.org/api/v1/source_files/process", form);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const form = new FormData();
form.append('file', fs.createReadStream('updated_translations.json'));
form.append('file_path', 'src/locales/en.json');
form.append('file_tag_name', 'frontend');
form.append('callback_url', 'https://your-app.com/webhooks/complete');
const response = await axios.put('https://app.ptc.wpml.org/api/v1/source_files/process', form, {
headers: {
...form.getHeaders(),
'Authorization': 'Bearer YOUR_API_TOKEN'
}
});
console.log(response.data);Unterstützte Dateiformate
Der Endpunkt unterstützt verschiedene übersetzbare Dateiformate, darunter unter anderem JSON-, PO/POT-, XLIFF- und Properties-Dateien. Die Validierung des Dateiformats erfolgt während des Uploads, um die Kompatibilität sicherzustellen.
Verwenden Sie den Endpunkt Unterstützte Dateiformate auflisten, um die vollständige Liste der unterstützten Formate abzurufen.
Übersetzungsstatus abrufen
Ruft den aktuellen Übersetzungsfortschritt für eine bestimmte Quelldatei ab, einschließlich des Fertigstellungsgrads und des allgemeinen Verarbeitungsstatus.
Dies ist nützlich für:
- Fortschrittsüberwachung – Verfolgung des Übersetzungsfortschritts bei lang laufenden Übersetzungsjobs
- UI-Aktualisierungen – Anzeige des prozentualen Fortschritts in Ihrer Anwendung
- Workflow-Integration – Auslösen von Aktionen, wenn die Übersetzung einen definierten Schwellenwert erreicht
HTTP-Anfrage
GET https://app.ptc.wpml.org/api/v1/source_files/translation_statusParameter
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
file_path |
string | Ja | Der Pfad zur Quelldatei innerhalb des Projekts. |
file_tag_name |
string | Nein | Der Name des Datei-Tags. Wenn nicht angegeben, wird das Standard-Datei-Tag des Projekts verwendet. |
Antworten
Erfolgsantwort
{
"translation_status": {
"status": "completed",
"completeness": 100
}
}Antwortschema
| Feld | Typ | Beschreibung |
|---|---|---|
translation_status.status |
string | Der aktuelle Verarbeitungsstatus der Quelldatei. Siehe Statuswerte unten. |
translation_status.completeness |
number | Der Prozentsatz der übersetzten Strings (0–100). Wird berechnet als (completed_translatable_strings / total_translatable_strings) × 100. |
Statuswerte
Das Feld status kann die folgenden Werte enthalten:
| Status | Beschreibung |
|---|---|
pending |
Die Quelldatei wartet auf die Verarbeitung. |
processing |
Die Übersetzung ist derzeit in Arbeit. |
completed |
Alle Übersetzungen wurden abgeschlossen. |
failed |
Beim Übersetzungsprozess sind Fehler aufgetreten. |
Fehlerantworten
Quelldatei nicht gefunden
{
"error": "Source file not found"
}Nicht autorisiert
{
"error": "Unauthorized access. Please provide a valid API token."
}Verboten
{
"error": "Access denied. Insufficient permissions."
}Ungültige Parameter
{
"error": "Invalid parameters provided."
}Beispielanfragen
Einfache Anfrage:
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files/translation_status?file_path=locales/en.po" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json"Anfrage mit Datei-Tag:
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files/translation_status?file_path=locales/en.po&file_tag_name=frontend" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json"Codebeispiele
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files/translation_status?file_path=locales/en.po&file_tag_name=frontend" \
-H "Authorization: Bearer YOUR_API_TOKEN"require 'net/http'
require 'uri'
uri = URI('https://app.ptc.wpml.org/api/v1/source_files/translation_status')
uri.query = URI.encode_www_form(file_path: 'locales/en.po', file_tag_name: 'frontend')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer YOUR_API_TOKEN'
response = http.request(request)
require 'json'
data = JSON.parse(response.body)
puts "Translation #{data['translation_status']['completeness']}% complete"import requests
headers = {
'Authorization': 'Bearer YOUR_API_TOKEN'
}
params = {
'file_path': 'locales/en.po',
'file_tag_name': 'frontend'
}
response = requests.get('https://app.ptc.wpml.org/api/v1/source_files/translation_status',
headers=headers, params=params)
data = response.json()
print(f"Translation {data['translation_status']['completeness']}% complete")<?php
$params = http_build_query([
'file_path' => 'locales/en.po',
'file_tag_name' => 'frontend'
]);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.ptc.wpml.org/api/v1/source_files/translation_status?{$params}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_TOKEN'
],
]);
$response = curl_exec($curl);
curl_close($curl);
$data = json_decode($response, true);
echo "Translation " . $data['translation_status']['completeness'] . "% complete";
?>import okhttp3.*;
OkHttpClient client = new OkHttpClient();
HttpUrl url = HttpUrl.parse("https://app.ptc.wpml.org/api/v1/source_files/translation_status")
.newBuilder()
.addQueryParameter("file_path", "locales/en.po")
.addQueryParameter("file_tag_name", "frontend")
.build();
Request request = new Request.Builder()
.url(url)
.addHeader("Authorization", "Bearer YOUR_API_TOKEN")
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());package main
import (
"fmt"
"io"
"net/http"
)
func main() {
req, _ := http.NewRequest("GET", "https://app.ptc.wpml.org/api/v1/source_files/translation_status", nil)
q := req.URL.Query()
q.Add("file_path", "locales/en.po")
q.Add("file_tag_name", "frontend")
req.URL.RawQuery = q.Encode()
req.Header.Add("Authorization", "Bearer YOUR_API_TOKEN")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_TOKEN");
var response = await client.GetAsync("https://app.ptc.wpml.org/api/v1/source_files/translation_status?file_path=locales/en.po&file_tag_name=frontend");
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);const axios = require('axios');
const response = await axios.get('https://app.ptc.wpml.org/api/v1/source_files/translation_status', {
headers: { 'Authorization': 'Bearer YOUR_API_TOKEN' },
params: {
file_path: 'locales/en.po',
file_tag_name: 'frontend'
}
});
console.log(`Translation ${response.data.translation_status.completeness}% complete`);Alle Übersetzungen herunterladen
Lädt alle übersetzten Dateien für eine bestimmte Quelldatei als ZIP-Archiv herunter.
Dieser Endpunkt erstellt und liefert ein komprimiertes Archiv, das alle Übersetzungsdateien in den Zielsprachen für die angegebene Quelldatei enthält.
Wenn für die Datei keine Übersetzungen verfügbar sind, gibt die Anfrage einen 404 Not Found-Fehler zurück.
HTTP-Anfrage
GET https://app.ptc.wpml.org/api/v1/source_files/download_translationsParameter
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
file_path |
string | Ja | Der Pfad zur Quelldatei innerhalb des Projekts. |
file_tag_name |
string | Nein | Der Name des Datei-Tags. Wenn nicht angegeben, wird das Standard-Datei-Tag des Projekts verwendet. Eine Quelldatei wird durch die Kombination aus file_path und file_tag_name eindeutig identifiziert. |
Antworten
Erfolgsantwort
{
"status": "processing",
"message": "Translations are still in progress. Please retry after the specified delay.",
"retry_after": 30
}Die PTC verarbeitet Übersetzungen asynchron. In der Regel gibt es eine kurze Wartezeit zwischen dem Hochladen einer Quelldatei und der Verfügbarkeit der Übersetzungen zum Download.
Wenn dies geschieht, warten Sie die in Retry-After angegebene Anzahl an Sekunden.
Fehlerantworten
Quelldatei nicht gefunden
{
"error": "Source file not found"
}Keine Übersetzungen verfügbar
{
"error": "No translations are available for this source file"
}Nicht autorisiert
{
"error": "Unauthorized access. Please provide a valid API token."
}Verboten
{
"error": "Access denied. Insufficient permissions."
}Ungültige Parameter
{
"error": "Invalid parameters provided."
}Beispielanfragen
Einfache Anfrage:
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files/download_translations?file_path=locales/en.po" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-o translations.zipAnfrage mit Datei-Tag:
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files/download_translations?file_path=locales/en.po&file_tag_name=frontend" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json" \
-o frontend-translations.zipCodebeispiele
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files/download_translations?file_path=locales/en.po&file_tag_name=frontend" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-o translations.zip
# 200 -> saves the zip; 202 -> {"status":"processing","retry_after":N} (retry later);
# 404 -> {"error":"No translations are available for this source file"}require 'net/http'
require 'uri'
uri = URI('https://app.ptc.wpml.org/api/v1/source_files/download_translations')
uri.query = URI.encode_www_form(file_path: 'locales/en.po', file_tag_name: 'frontend')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Get.new(uri)
request['Authorization'] = 'Bearer YOUR_API_TOKEN'
response = http.request(request)
if response.code == '200'
File.binwrite('translations.zip', response.body)
puts 'Translations downloaded successfully'
elsif response.code == '202'
puts 'Translations are still processing — retry after the Retry-After interval'
elsif response.code == '404'
puts 'No translations are available for this source file yet'
endimport requests
headers = {
'Authorization': 'Bearer YOUR_API_TOKEN'
}
params = {
'file_path': 'locales/en.po',
'file_tag_name': 'frontend'
}
response = requests.get('https://app.ptc.wpml.org/api/v1/source_files/download_translations',
headers=headers, params=params)
if response.status_code == 200:
with open('translations.zip', 'wb') as f:
f.write(response.content)
print('Translations downloaded successfully')
elif response.status_code == 202:
print('Translations are still processing — retry after the Retry-After interval')
elif response.status_code == 404:
print('No translations are available for this source file yet')<?php
$params = http_build_query([
'file_path' => 'locales/en.po',
'file_tag_name' => 'frontend'
]);
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://app.ptc.wpml.org/api/v1/source_files/download_translations?{$params}",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_TOKEN'
],
]);
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
if ($httpCode === 200) {
file_put_contents('translations.zip', $response);
echo 'Translations downloaded successfully';
} elseif ($httpCode === 202) {
echo 'Translations are still processing — retry after the Retry-After interval';
} elseif ($httpCode === 404) {
echo 'No translations are available for this source file yet';
}
?>import okhttp3.*;
import java.nio.file.*;
OkHttpClient client = new OkHttpClient();
HttpUrl url = HttpUrl.parse("https://app.ptc.wpml.org/api/v1/source_files/download_translations")
.newBuilder()
.addQueryParameter("file_path", "locales/en.po")
.addQueryParameter("file_tag_name", "frontend")
.build();
Request request = new Request.Builder()
.url(url)
.addHeader("Authorization", "Bearer YOUR_API_TOKEN")
.build();
Response response = client.newCall(request).execute();
if (response.code() == 200) {
Files.write(Paths.get("translations.zip"), response.body().bytes());
System.out.println("Translations downloaded successfully");
} else if (response.code() == 202) {
System.out.println("Translations are still processing — retry after the Retry-After interval");
} else if (response.code() == 404) {
System.out.println("No translations are available for this source file yet");
}package main
import (
"fmt"
"io"
"net/http"
"os"
)
func main() {
req, _ := http.NewRequest("GET", "https://app.ptc.wpml.org/api/v1/source_files/download_translations", nil)
q := req.URL.Query()
q.Add("file_path", "locales/en.po")
q.Add("file_tag_name", "frontend")
req.URL.RawQuery = q.Encode()
req.Header.Add("Authorization", "Bearer YOUR_API_TOKEN")
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
if resp.StatusCode == 200 {
body, _ := io.ReadAll(resp.Body)
os.WriteFile("translations.zip", body, 0644)
fmt.Println("Translations downloaded successfully")
} else if resp.StatusCode == 202 {
fmt.Println("Translations are still processing — retry after the Retry-After interval")
} else if resp.StatusCode == 404 {
fmt.Println("No translations are available for this source file yet")
}
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_TOKEN");
var response = await client.GetAsync("https://app.ptc.wpml.org/api/v1/source_files/download_translations?file_path=locales/en.po&file_tag_name=frontend");
if ((int)response.StatusCode == 200) {
var bytes = await response.Content.ReadAsByteArrayAsync();
File.WriteAllBytes("translations.zip", bytes);
Console.WriteLine("Translations downloaded successfully");
} else if ((int)response.StatusCode == 202) {
Console.WriteLine("Translations are still processing — retry after the Retry-After interval");
} else if ((int)response.StatusCode == 404) {
Console.WriteLine("No translations are available for this source file yet");
}const axios = require('axios');
const fs = require('fs');
const response = await axios.get('https://app.ptc.wpml.org/api/v1/source_files/download_translations', {
headers: { 'Authorization': 'Bearer YOUR_API_TOKEN' },
responseType: 'stream',
validateStatus: (s) => s === 200 || s === 202 || s === 404
});
if (response.status === 200) {
response.data.pipe(fs.createWriteStream('translations.zip'));
console.log('Translations downloaded successfully');
} else if (response.status === 202) {
console.log('Translations are still processing — retry after the Retry-After interval');
} else if (response.status === 404) {
console.log('No translations are available for this source file yet');
}Quelldateien im Stapel hochladen
Lädt ein ZIP-Archiv hoch, das mehrere übersetzbare Dateien enthält. Jede Datei im Archiv wird extrahiert, validiert und verarbeitet. Unterstützte Formate werden automatisch erkannt.
Dies ist die Batch-Version von Quelldatei verarbeiten, die entwickelt wurde, um umfangreiche Aktualisierungen zu beschleunigen.
Zusätzliche Informationen
- Wenn eine Datei mit einer vorhandenen Quelldatei übereinstimmt, wird diese mit dem neuen Inhalt aktualisiert und die Übersetzungen werden erneut angestoßen.
- Wenn eine Datei unterstützt wird, aber mit keiner vorhandenen Quelldatei übereinstimmt, wird sie zur Liste
not_found_fileshinzugefügt und ignoriert. - Dateien mit nicht unterstützten Formaten werden unter
unsupported_filesaufgelistet und ignoriert. - Dateien mit ungültigem Inhalt werden ebenfalls unter
unsupported_filesaufgelistet und ignoriert. - Die Verarbeitung großer Archive kann länger dauern. Dateien werden nacheinander verarbeitet, um die Systemressourcen zu schonen. Daher ist es am besten, sehr große Uploads (mehr als 100 Dateien) in kleinere Batches aufzuteilen. Alle Dateien im Archiv werden auf automatische Übersetzung eingestellt.
- Das hochgeladene ZIP-Archiv muss gültig und lesbar sein. Alle darin enthaltenen Dateien müssen in einem unterstützten Format vorliegen. Dateinamen sollten keine Sonderzeichen enthalten, die Pfadfehler verursachen könnten.
- Wenn ein
callback_urlangegeben ist, wird für jede verarbeitete Quelldatei einePOST-Anfrage mit ihren Ergebnissen gesendet.
HTTP-Anfrage
POST https://app.ptc.wpml.org/api/v1/source_files/bulkParameter
| Parameter | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
zip_file |
file | Ja | Ein ZIP-Archiv, das die hochzuladenden Quelldateien enthält. Es muss eine gültige ZIP-Datei sein. |
file_tag_name |
string | Nein | Der Name des Datei-Tags, das allen Quelldateien im Archiv zugewiesen werden soll. Wenn nicht angegeben, wird das Standard-Datei-Tag des Projekts verwendet. Jede Quelldatei wird eindeutig durch die Kombination aus file_path und file_tag_name identifiziert. |
callback_url |
string | Nein | Die URL, die Webhook-Benachrichtigungen empfängt, wenn die jeweilige Datei verarbeitet wird. |
Erwartete Struktur der ZIP-Datei
Die ZIP-Datei kann Quelldateien in einer beliebigen Verzeichnisstruktur enthalten. Die Verzeichnisstruktur bleibt erhalten und die Dateien werden rekursiv verarbeitet.
Beispielhafte ZIP-Struktur:
source-files.zip
├── locales/
│ ├── messages-en.po
│ ├── validation-en.po
│ └── admin-en.po
├── frontend/
│ ├── components-en.json
│ └── pages-en.json
│ └── not-found-en.json
├── app-strings-en.properties
└── readme.txt (will be ignored)
Unterstützte Dateitypen:
- JSON:
.json-Dateien - gettext:
.po-,.pot-Dateien - Properties:
.properties-Dateien - YAML:
.yml-,.yaml-Dateien - XML:
.xml-Dateien - Strings:
.strings-Dateien - XLIFF:
.xliff-,.xlf-Dateien - CSV:
.csv-Dateien - PHP:
.php-Dateien
Antworten
Erfolgsantwort
{
"success": true,
"file_tag": {
"id": 456,
"name": "backend"
},
"processed_files": [
{
"id": 123,
"file_path": "locales/messages-en.po",
"created_at": "2024-01-15T10:30:00.000Z",
"file_tag": {
"id": 456,
"name": "backend"
}
},
{
"id": 124,
"file_path": "locales/validation-en.po",
"created_at": "2024-01-15T10:30:05.000Z",
"file_tag": {
"id": 456,
"name": "backend"
}
}
],
"unsupported_files": [
"readme.txt",
"config.ini"
],
"not_found_files": ["frontend/not-found-en.json"]
}Antwortschema
| Feld | Typ | Beschreibung |
|---|---|---|
success |
boolean | Gibt an, ob der Bulk-Upload erfolgreich war. |
file_tag |
object | Die Informationen zum Datei-Tag. |
file_tag.id |
integer | Die Kennung des Datei-Tags. |
file_tag.name |
string | Der Name des Datei-Tags. |
processed_files |
array[object] | Ein Array von Quelldateien, die erfolgreich verarbeitet wurden. |
processed_files[].id |
integer | Die eindeutige Kennung für die erstellte Quelldatei. |
processed_files[].file_path |
string | Der Pfad der Quelldatei unter Beibehaltung der ursprünglichen ZIP-Struktur. |
processed_files[].created_at |
string | Ein ISO-8601-Zeitstempel, der angibt, wann die Quelldatei erstellt wurde. |
processed_files[].file_tag |
object | Die Informationen zum Datei-Tag. |
processed_files[].file_tag.id |
integer | Die Kennung des Datei-Tags. |
processed_files[].file_tag.name |
string | Der Name des Datei-Tags. |
unsupported_files |
array[string] | Ein Array von Dateinamen, die kein unterstütztes Format haben. |
not_found_files |
array[string] | Ein Array von unterstützten Dateien, die mit keiner vorhandenen Quelldatei übereinstimmten und ignoriert wurden. |
Fehlerantworten
Ungültige ZIP-Datei
{
"success": false,
"error": "File format is invalid",
"processed_files": [],
"unsupported_files": []
}Verarbeitung fehlgeschlagen
{
"success": false,
"error": "Failed to process ZIP archive",
"processed_files": [],
"unsupported_files": []
}Nicht autorisiert
{
"error": "Unauthorized access. Please provide a valid API token."
}Zugriff verweigert
{
"error": "Access denied. Insufficient permissions."
}Webhook-Callback
Wenn eine callback_url angegeben wird, wird für jede verarbeitete Datei eine POST-Anfrage gesendet.
Body der Callback-Anfrage (pro Datei):
{
"source_file_id": 123,
"status": "completed",
"file_tag_name": "backend",
"download_url": "https://app.ptc.wpml.org/api/v1/source_files/download_translations?file_path=locales/messages-en.po&file_tag_name=backend",
"file_path": "locales/messages-en.po"
}Beispielanfragen
Einfacher Bulk-Upload:
curl -X POST "https://app.ptc.wpml.org/api/v1/source_files/bulk" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "zip_file=@source-files.zip" \
-F "file_tag_name=backend"Anfrage mit Callback-URL:
curl -X POST "https://app.ptc.wpml.org/api/v1/source_files/bulk" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "zip_file=@translations.zip" \
-F "file_tag_name=localization" \
-F "callback_url=https://your-app.com/webhooks/bulk-complete"Code-Beispiele
curl -X POST "https://app.ptc.wpml.org/api/v1/source_files/bulk" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "zip_file=@source-files.zip" \
-F "file_tag_name=backend" \
-F "callback_url=https://your-app.com/webhooks/complete"require 'net/http'
require 'uri'
uri = URI('https://app.ptc.wpml.org/api/v1/source_files/bulk')
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri)
request['Authorization'] = 'Bearer YOUR_API_TOKEN'
request.set_form(
[
['zip_file', File.open('source-files.zip')],
['file_tag_name', 'backend'],
['callback_url', 'https://your-app.com/webhooks/complete']
],
'multipart/form-data'
)
response = http.request(request)
puts response.bodyimport requests
headers = {'Authorization': 'Bearer YOUR_API_TOKEN'}
files = {'zip_file': open('source-files.zip', 'rb')}
data = {
'file_tag_name': 'backend',
'callback_url': 'https://your-app.com/webhooks/complete'
}
response = requests.post('https://app.ptc.wpml.org/api/v1/source_files/bulk',
headers=headers, files=files, data=data)
print(response.json())<?php
$post_data = [
'zip_file' => new CURLFile('source-files.zip'),
'file_tag_name' => 'backend',
'callback_url' => 'https://your-app.com/webhooks/complete'
];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => 'https://app.ptc.wpml.org/api/v1/source_files/bulk',
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => $post_data,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_TOKEN'
],
]);
$response = curl_exec($curl);
curl_close($curl);
print_r(json_decode($response, true));
?>import okhttp3.*;
import java.io.File;
OkHttpClient client = new OkHttpClient();
MultipartBody body = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("zip_file", "source-files.zip",
RequestBody.create(new File("source-files.zip"), MediaType.parse("application/octet-stream")))
.addFormDataPart("file_tag_name", "backend")
.addFormDataPart("callback_url", "https://your-app.com/webhooks/complete")
.build();
Request request = new Request.Builder()
.url("https://app.ptc.wpml.org/api/v1/source_files/bulk")
.addHeader("Authorization", "Bearer YOUR_API_TOKEN")
.post(body)
.build();
Response response = client.newCall(request).execute();
System.out.println(response.body().string());package main
import (
"bytes"
"fmt"
"io"
"mime/multipart"
"net/http"
"os"
)
func main() {
var buf bytes.Buffer
w := multipart.NewWriter(&buf)
file, _ := os.Open("source-files.zip")
defer file.Close()
fw, _ := w.CreateFormFile("zip_file", "source-files.zip")
io.Copy(fw, file)
w.WriteField("file_tag_name", "backend")
w.WriteField("callback_url", "https://your-app.com/webhooks/complete")
w.Close()
req, _ := http.NewRequest("POST", "https://app.ptc.wpml.org/api/v1/source_files/bulk", &buf)
req.Header.Add("Authorization", "Bearer YOUR_API_TOKEN")
req.Header.Add("Content-Type", w.FormDataContentType())
resp, _ := http.DefaultClient.Do(req)
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(string(body))
}
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.IO;
var client = new HttpClient();
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "YOUR_API_TOKEN");
var form = new MultipartFormDataContent();
form.Add(new StreamContent(File.OpenRead("source-files.zip")), "zip_file", "source-files.zip");
form.Add(new StringContent("backend"), "file_tag_name");
form.Add(new StringContent("https://your-app.com/webhooks/complete"), "callback_url");
var response = await client.PostAsync("https://app.ptc.wpml.org/api/v1/source_files/bulk", form);
var content = await response.Content.ReadAsStringAsync();
Console.WriteLine(content);const axios = require('axios');
const FormData = require('form-data');
const fs = require('fs');
const form = new FormData();
form.append('zip_file', fs.createReadStream('source-files.zip'));
form.append('file_tag_name', 'backend');
form.append('callback_url', 'https://your-app.com/webhooks/complete');
const response = await axios.post('https://app.ptc.wpml.org/api/v1/source_files/bulk', form, {
headers: {
...form.getHeaders(),
'Authorization': 'Bearer YOUR_API_TOKEN'
}
});
console.log(response.data);Weiter:
Finden Sie unterstützte Dateiformate und Zielsprachen über die API →