Quelldateien über die API hochladen und verwalten
Nutzen Sie diese API, um neue Quelldateien hochzuladen, veraltete Dateien zu ersetzen, den Übersetzungsfortschritt zu verfolgen und fertige Übersetzungen herunterzuladen.
Ganz gleich, ob Sie eine einzelne Datei verwalten oder einen Workflow für die kontinuierliche Übersetzung automatisieren – diese API gibt Ihnen die volle Kontrolle darüber, welche Inhalte Sie zur Übersetzung senden und wie Sie die Übersetzungen erhalten.
API-Quick-Links
Wie die PTC API Quelldateien identifiziert und organisiert
Die PTC-API nutzt 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, eindeutig definiert und einfach zu verwalten ist.
File-Tags
File-Tags sind eine flexible Methode, um Quelldateien in Übersetzungsprojekten zu gruppieren und zu organisieren. Sie können diese wie Kategorien verwenden, um sie an Ihre Workflow-Anforderungen anzupassen. File-Tags können zum Beispiel Folgendes kennzeichnen:
- Versionskontrolle:
v1.0,beta,production - Feature-Branches:
user-auth,dashboard-redesign - Anwendungskontext:
mobile-app,admin-panel,marketing - Team-Zugehörigkeit:
frontend-team,content-team - Workflow-Status:
approved,pending-review,priority-high
Die Angabe von File-Tag-Namen ist bei den meisten API-Operationen optional. Dennoch besitzt jede Quelldatei immer mindestens einen Tag. Ein Standard-File-Tag wird automatisch erstellt und zugewiesen, wenn ein Projekt eingerichtet wird. Dieses Standardverhalten sorgt dafür, dass Projekte selbst in einfachen Setups organisiert bleiben, während es Ihnen gleichzeitig ermöglicht, bei Bedarf fortgeschrittenere Tagging-Strukturen aufzubauen.
File-Tag-Name + Dateipfad
Jede Quelldatei wird durch die Kombination aus ihrem Datei-Tag-Namen und ihrem Dateipfad eindeutig identifiziert.
- Wenn Sie beim Hochladen oder Verarbeiten einer Datei keinen benutzerdefinierten File-Tag angeben, wird automatisch der Standard-Tag zugewiesen.
- Der Tag-Name und der Pfad einer Datei definieren zusammen ihre Identität. Diese Kombination stellt sicher, dass jede Datei innerhalb Ihres Projekts einzigartig ist, selbst wenn verschiedene Versionen oder Kontexte denselben Dateipfad verwenden.
Abfrageparameter
Beim Abrufen einer bestimmten Datei können die entsprechenden Endpunkte Abfrageparameter akzeptieren, wie zum Beispiel:
file_tag_name– Der mit der Datei verknüpfte Tagfile_path– Der Pfad zur Datei
Diese Parameter ermöglichen es Ihnen, die korrekten Dateien in 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, deren Status prüfen oder bestimmte Dateien basierend auf Tag, Pfad oder Upload-Methode finden möchten.
HTTP-Request
GET https://app.ptc.wpml.org/api/v1/source_filesParameter
| Parameter | Typ | Erforderlich | Standard | 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 exaktem Dateipfad. |
upload_origin |
string | Nein | – | Filtert danach, wie die Datei hochgeladen wurde. Zulässige Werte sind: git, manual, api. |
Antworten
Erfolgreiche Antwort
{
"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
}
}Antwort-Schema
Quelldatei-Objekt:
| Feld | Typ | Beschreibung |
|---|---|---|
id |
integer | Die eindeutige Kennung für die 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 alle zusätzlichen 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 der Ü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."
}Verboten
{
"error": "Access denied. Insufficient permissions."
}Ungültige Parameter
{
"error": "Invalid parameters provided."
}Beispiel-Requests
Einfacher Request:
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json"Gefilterter Request:
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);Übersetzungs-Strings abrufen
Ruft alle übersetzbaren Strings aus einer bestimmten Quelldatei zusammen mit ihren vorhandenen Übersetzungen in allen Zielsprachen ab.
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 | Standard | Beschreibung |
|---|---|---|---|---|
file_path |
string | Ja | – | Der Pfad zur Quelldatei innerhalb des Projekts. |
file_tag_name |
string | Nein | – | Der Name des Datei-Tags. Falls nicht angegeben, wird der Standard-Tag des Projekts verwendet. |
page |
integer | Nein | 1 |
Die Seitenzahl für die Paginierung (als Cursor verwendet). Muss größer als 0 sein. |
q |
string | Nein | – | Die Suchanfrage, um Übersetzungs-Strings nach ihrem Ausgangstext zu filtern. |
Antworten
Erfolgreiche Antwort
{
"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 Übersetzungs-String-Objekte (paginiert, max. 500 pro Seite). |
translation_strings[].source |
string | Der zu übersetzende Original-Ausgangstext. |
translation_strings[].translations |
object | Ein Hash von Übersetzungen, wobei die Schlüssel 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."
}Verboten
{
"error": "Access denied. Insufficient permissions."
}Ungültige Parameter
{
"error": "Invalid parameters provided."
}Beispiel-Anfragen
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"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"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"Code-Beispiele
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, damit sie für die Übersetzung bereit ist.
Dieser Endpunkt erstellt den Dateieintrag und richtet die Übersetzungskonfiguration ein, fügt jedoch nicht den tatsächlichen Dateiinhalt bei.
Nachdem Sie die Datei erstellt haben, 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 Pfadmuster für die Ausgabedateien der Übersetzungen. Verwenden Sie {{lang}} als Platzhalter für den Sprachcode. |
translations |
array[object] | Nein | Bereits vorhandene Übersetzungsdateien, die zusammen mit der Quelldatei hochgeladen werden sollen. Diese Dateien werden wie bereitgestellt gespeichert und ihre Strings werden nicht von PTC neu übersetzt. Beachten Sie, dass die Bereitstellung vorhandener Übersetzungen nicht empfohlen wird, da PTC bessere Ergebnisse erzielt, wenn es den vollen Kontext Ihres Projekts nutzen und von Grund auf neu ü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 | Zusätzliche Konfigurationen für Ausgabedateien in spezifischen Formaten. Um zu sehen, welche Formate zusätzliche Ausgabedateien unterstützen, nutzen Sie den Endpunkt Unterstützte Dateiformate auflisten. Bei nicht unterstützten Formaten wird dieses Feld ignoriert. |
additional_translation_files[].type |
string | Ja | Weitere Details finden Sie unter unterstützte Dateiformate. |
additional_translation_files[].path |
string | Ja | Das Pfadmuster für die Datei. |
Antworten
Erfolgreiche Antwort
{
"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."
}Verboten
{
"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"Anfrage mit Callback-URL:
curl -X POST "https://app.ptc.wpml.org/api/v1/source_files" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-F "file_path=src/locales/messages.po" \
-F "output_file_path=locales/{lang}/messages.po" \
-F "callback_url=https://your-app.com/webhooks/translation-complete"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[mo]=locales/{lang}/messages.mo" \
-F "additional_translation_files[json]=locales/{lang}/messages.json"Code-Beispiele
- JavaScript (FormData)
- Python (requests)
- PHP (cURL)
- Node.js (axios)
- Callback-Anfrage-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 vorhanden sein. Falls Sie diese noch nicht erstellt haben, lesen Sie bitte 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 der angegebenen Erweiterung entspricht. Wenn die Dateierweiterung beispielsweise .json lautet, muss der hochgeladene Inhalt gültiges JSON sein. |
file_path |
string | Ja | Der Pfad zur existierenden Quelldatei im Projekt, die aktualisiert werden soll. |
file_tag_name |
string | Nein | Der Name des Datei-Tags, das der Quelldatei zugeordnet ist. Falls nicht angegeben, wird das Standard-Datei-Tag des Projekts verwendet. |
callback_url |
string | Nein | Die URL, die Webhook-Benachrichtigungen erhält, sobald die Dateiverarbeitung abgeschlossen ist. |
Antworten
Erfolgreiche Antwort
{
"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 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 | Die Kennung des Datei-Tags. |
source_file.file_tag.name |
string | Der Name des Datei-Tags. |
Fehlerantworten
Quelldatei nicht gefunden
{
"errors": {
"file": ["File format is invalid or not supported"]
}
}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 angelegt 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 wird, sendet PTC eine POST-Anfrage an diese URL, sobald die Verarbeitung abgeschlossen ist.
Callback-Anfrage-Body:
{
"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"
}Beispiel-Anfragen
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"Code-Beispiele
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 zu erhalten.
Ü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 Aufträgen
- UI-Updates – Anzeige von Fertigstellungsprozentsätzen 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. Falls nicht angegeben, wird das Standard-Datei-Tag des Projekts verwendet. |
Antworten
Erfolgsantwort
{
"translation_status": {
"status": "completed",
"completeness": 100
}
}Antwort-Schema
| 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). Berechnet als (completed_translatable_strings / total_translatable_strings) × 100. |
Statuswerte
Das Feld status kann folgende 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."
}Beispiel-Anfragen
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"Code-Beispiele
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 zurück, das alle Übersetzungsdateien in den Zielsprachen für die angegebene Quelldatei enthält.
Falls keine Übersetzungen für die Datei 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. Falls nicht angegeben, wird der Standard-Datei-Tag des Projekts verwendet. Eine Quelldatei wird eindeutig durch die Kombination aus file_path und file_tag_name identifiziert. |
Antworten
Erfolgreiche Antwort
{
"status": "processing",
"message": "Translations are still in progress. Please retry after the specified delay.",
"retry_after": 30
}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 eintritt, 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."
}Beispiel-Anfragen
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.zipCode-Beispiele
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 per Bulk-Upload 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 darauf ausgelegt ist, umfangreiche Aktualisierungen zu beschleunigen.
Zusätzliche Informationen
- Wenn eine Datei mit einer vorhandenen Quelldatei übereinstimmt, wird sie mit dem neuen Inhalt aktualisiert und die Übersetzungen werden erneut ausgelöst.
- Wenn eine Datei unterstützt wird, aber mit keiner vorhandenen Quelldatei übereinstimmt, wird sie der Liste
not_found_fileshinzugefügt und ignoriert. - Dateien mit nicht unterstützten Formaten werden unter
unsupported_filesaufgeführt und ignoriert. - Dateien mit ungültigem Inhalt werden ebenfalls unter
unsupported_filesaufgeführt und ignoriert. - Große Archive benötigen unter Umständen mehr Zeit für die Verarbeitung. Dateien werden nacheinander verarbeitet, um Ressourcen zu verwalten. Daher ist es am besten, sehr große Uploads (mehr als 100 Dateien) in kleinere Batches aufzuteilen. Alle Dateien im Archiv werden so eingestellt, dass sie automatisch übersetzt werden.
- Das hochgeladene ZIP-Archiv muss gültig und lesbar sein. Alle enthaltenen Dateien müssen in einem unterstützten Format vorliegen. Dateinamen sollten keine Sonderzeichen enthalten, die Pfadprobleme verursachen könnten.
- Wenn eine
callback_urlangegeben wird, wird für jede verarbeitete Quelldatei einePOST-Anfrage mit den entsprechenden 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, der allen Quelldateien im Archiv zugewiesen werden soll. Falls 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 jede Datei verarbeitet wurde. |
Erwartete ZIP-Dateistruktur
Die ZIP-Datei kann Quelldateien in einer beliebigen Verzeichnisstruktur enthalten. Die Verzeichnisstruktur bleibt erhalten und Dateien werden rekursiv verarbeitet.
Beispiel für eine 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
Erfolgreiche Antwort
{
"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"]
}Antwort-Schema
| Feld | Typ | Beschreibung |
|---|---|---|
success |
boolean | Gibt an, ob die Bulk-Upload-Operation 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."
}Verboten
{
"error": "Access denied. Insufficient permissions."
}Webhook-Callback
Wenn eine callback_url angegeben wird, wird für jede verarbeitete Datei eine POST-Anfrage gesendet.
Callback-Anfrage-Body (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"
}Beispiel-Anfragen
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:
Unterstützte Dateiformate und Zielsprachen über die API finden →