העלאה וניהול של קובצי מקור דרך ה־API
השתמשו ב־API זה כדי להעלות קובצי מקור חדשים, להחליף קבצים מיושנים, לעקוב אחר התקדמות התרגום ולהוריד תרגומים שהושלמו.
בין אם אתם מנהלים קובץ בודד או מבצעים אוטומציה של תהליך לוקליזציה מתמשכת, API זה מעניק לכם שליטה מלאה על התוכן שאתם שולחים לתרגום ועל האופן שבו אתם מקבלים את התרגומים.
קישורים מהירים ל־API
כיצד ה־API של PTC מזהה ומארגן קובצי מקור
ה־API של PTC משתמש במערכת גמישה המבוססת על תגיות קובץ ונתיבי קבצים. פרמטרים אלו פועלים יחד כדי להבטיח שכל קובץ שאתם מעלים, מעדכנים או מבקשים יהיה מוגדר בבירור וקל לניהול.
תגיות קובץ
תגיות קובץ הן דרך גמישה לקבץ ולארגן קובצי מקור בפרויקטים של תרגום. תוכלו להשתמש בהן כמו בקטגוריות כדי להתאים לצרכי תהליך העבודה שלכם. לדוגמה, תגיות קובץ יכולות לציין:
- בקרת גרסאות:
v1.0,beta,production - ענפי פיצ'רים:
user-auth,dashboard-redesign - הקשר האפליקציה:
mobile-app,admin-panel,marketing - בעלות צוותית:
frontend-team,content-team - מצב תהליך העבודה:
approved,pending-review,priority-high
שמות של תגיות קובץ הם אופציונליים ברוב פעולות ה־API. עם זאת, לכל קובץ מקור יש תמיד לפחות תגית אחת. תגית קובץ כברירת מחדל נוצרת ומוקצית באופן אוטומטי בעת הקמת פרויקט. התנהגות ברירת מחדל זו שומרת על פרויקטים מאורגנים גם בהגדרות פשוטות, ובמקביל מאפשרת לכם לבנות מבני תיוג מתקדמים יותר בעת הצורך.
שם תגית קובץ + נתיב קובץ
כל קובץ מקור מזוהה באופן ייחודי על ידי השילוב של שם תגית הקובץ ונתיב הקובץ שלו.
- אם לא תספקו תגית קובץ מותאמת אישית בעת העלאה או עיבוד של קובץ, תגית ברירת המחדל תוקצה באופן אוטומטי.
- שם התגית + הנתיב של הקובץ יחד מגדירים את זהותו. שילוב זה מבטיח שכל קובץ יהיה ייחודי בתוך הפרויקט שלכם, גם אם גרסאות או הקשרים שונים חולקים את אותו נתיב קובץ.
פרמטרי שאילתה
בעת אחזור קובץ מסוים, endpoints קשורים יכולים לקבל פרמטרי שאילתה כגון:
file_tag_name– התגית המשויכת לקובץfile_path– הנתיב לקובץ
פרמטרים אלו מאפשרים לכם לאתר ולאחזר במדויק את הקבצים הנכונים מהפרויקט שלכם.
פירוט כל קובצי המקור בפרויקט
מציג רשימה של כל קובצי המקור בפרויקט שלכם, עם אפשרויות לסינון, מיון וחלוקה לעמודים של התוצאות. זה שימושי כאשר אתם רוצים לעיין בקבצים שלכם, לבדוק את הסטטוס שלהם, או למצוא קבצים ספציפיים על בסיס תגית, נתיב או שיטת העלאה.
בקשת HTTP
GET https://app.ptc.wpml.org/api/v1/source_filesפרמטרים
| פרמטר | סוג | חובה | ברירת מחדל | תיאור |
|---|---|---|---|---|
page |
integer | לא | 1 |
מספר העמוד לחלוקה לעמודים. חייב להיות גדול מ־0. |
per_page |
integer | לא | 50 |
מספר הפריטים בכל עמוד. חייב להיות גדול מ־0. |
order_by |
string | לא | created_at |
השדה לפיו יתבצע המיון. ערכים מותרים: id, created_at, updated_at. |
sort |
string | לא | desc |
כיוון המיון. ערכים מותרים: asc, desc. |
file_path |
string | לא | – | מסנן לפי נתיב קובץ מדויק. |
upload_origin |
string | לא | – | מסנן לפי אופן העלאת הקובץ. ערכים מותרים כוללים: git, manual, api. |
תגובות
תגובת הצלחה
{
"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
}
}סכמת תגובה
אובייקט קובץ מקור:
| שדה | סוג | תיאור |
|---|---|---|
id |
integer | המזהה הייחודי של קובץ המקור. |
file_path |
string | הנתיב לקובץ המקור בתוך הפרויקט. |
translation_path |
string | התבנית עבור המיקום שבו יישמרו קבצים מתורגמים. |
additional_translation_files |
array[string] | הנתיבים עבור קבצי פלט נוספים כלשהם. |
status |
string | סטטוס העיבוד הנוכחי של קובץ המקור. |
upload_origin |
string | אופן העלאת הקובץ (git, manual, api). |
created_at |
string | חותמת זמן בתקן ISO 8601 המציינת מתי קובץ המקור נוצר במקור. |
updated_at |
string | חותמת זמן בתקן ISO 8601 המציינת מתי קובץ המקור עודכן לאחרונה. |
file_tag |
object | מידע אודות תגית הקובץ. |
file_tag.id |
integer | מזהה תגית הקובץ. |
file_tag.name |
string | שם תגית הקובץ. |
download_url |
string | כתובת ה־URL להורדת תרגומים עבור קובץ מקור זה. |
אובייקט חלוקה לעמודים:
| שדה | סוג | תיאור |
|---|---|---|
page |
integer | מספר העמוד הנוכחי. |
per_page |
integer | מספר הפריטים בכל עמוד. |
total |
integer | המספר הכולל של קובצי מקור. |
total_pages |
integer | המספר הכולל של עמודים. |
has_next_page |
boolean | האם קיים העמוד הבא. |
has_previous_page |
boolean | האם קיים עמוד קודם. |
תגובות שגיאה
לא מורשה (Unauthorized)
{
"error": "Unauthorized access. Please provide a valid API token."
}גישה נדחתה (Forbidden)
{
"error": "Access denied. Insufficient permissions."
}פרמטרים לא תקינים
{
"error": "Invalid parameters provided."
}בקשות לדוגמה
בקשה בסיסית:
curl -X GET "https://app.ptc.wpml.org/api/v1/source_files" \
-H "Authorization: Bearer YOUR_API_TOKEN" \
-H "Content-Type: application/json"בקשה מסוננת:
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"דוגמאות קוד
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);אחזור מחרוזות תרגום
מאחזר את כל המחרוזות הניתנות לתרגום מתוך קובץ מקור מסוים, יחד עם התרגומים הקיימים שלהן בכל שפות היעד.
endpoint זה שימושי לאחזור תוכן שדורש תרגום או שכבר תורגם. קובץ המקור מזוהה על ידי file_path ו־file_tag_name.
בקשת HTTP
GET https://app.ptc.wpml.org/api/v1/source_files/translation_stringsפרמטרים
| פרמטר | סוג | חובה | ברירת מחדל | תיאור |
|---|---|---|---|---|
file_path |
string | כן | – | הנתיב לקובץ המקור בתוך הפרויקט. |
file_tag_name |
string | לא | – | שם תגית הקובץ. אם לא סופק, נעשה שימוש בתגית ברירת המחדל של הפרויקט. |
page |
integer | לא | 1 |
מספר העמוד לחלוקה לעמודים (משמש כ־cursor). חייב להיות גדול מ־0. |
q |
string | לא | – | שאילתת החיפוש לסינון מחרוזות תרגום לפי טקסט המקור שלהן. |
תגובות
תגובת הצלחה
{
"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
}סכמת תגובה
| שדה | סוג | תיאור |
|---|---|---|
total_strings_count |
integer | המספר הכולל של מחרוזות הניתנות לתרגום בקובץ המקור. |
translation_strings |
array[object] | מערך של אובייקטי מחרוזות תרגום (מחולק לעמודים, מקסימום 500 לעמוד). |
translation_strings[].source |
string | טקסט המקור המקורי המיועד לתרגום. |
translation_strings[].translations |
object | hash של תרגומים שבו המפתחות הם קודי ISO של השפות והערכים הם הטקסט המתורגם. |
cursor |
integer | ה־cursor של העמוד הנוכחי המשמש לחלוקה לעמודים. |
תגובות שגיאה
קובץ המקור לא נמצא
{
"error": "Source file not found"
}לא מורשה (Unauthorized)
{
"error": "Unauthorized access. Please provide a valid API token."
}גישה נדחתה (Forbidden)
{
"error": "Access denied. Insufficient permissions."
}פרמטרים לא תקינים
{
"error": "Invalid parameters provided."
}בקשות לדוגמה
בקשה בסיסית:
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"בקשה עם תגית קובץ:
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"בקשה עם חלוקה לעמודים וחיפוש:
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"דוגמאות קוד
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);יצירת קובץ המקור
רושם קובץ מקור חדש בפרויקט שלכם כך שיהיה מוכן לתרגום.
endpoint זה יוצר את רשומת הקובץ ומגדיר את תצורת התרגום שלו, אך אינו מצרף את תוכן הקובץ עצמו.
לאחר יצירת הקובץ, תצטרכו להשתמש ב־endpoint עיבוד קובץ המקור כדי להעלות את התוכן ולהתחיל את תהליך התרגום.
בקשת HTTP
POST https://app.ptc.wpml.org/api/v1/source_filesפרמטרים
| פרמטר | סוג | חובה | תיאור |
|---|---|---|---|
file_path |
string | כן | הנתיב שבו קובץ המקור יישמר בפרויקט. חייב להיות בעל סיומת נתמכת. |
output_file_path |
string | כן | תבנית נתיב הפלט עבור קבצים מתורגמים. השתמשו ב־{{lang}} כמציין מיקום עבור קוד השפה. |
translations |
array[object] | לא | תרגומים קיימים שיועלו לצד קובץ המקור. קבצים אלו יישמרו כפי שסופקו, והמחרוזות שלהם לא יתורגמו מחדש על ידי PTC. שימו לב שסיפוק תרגומים קיימים אינו מומלץ, שכן PTC מפיקה תוצאות טובות יותר כאשר היא יכולה להשתמש בהקשר המלא של הפרויקט שלכם ולבצע תרגום מאפס. |
translations[].target_language_iso |
string | כן | קוד ה־ISO של שפת היעד עבור תרגום זה. תוכלו למצוא את הרשימה המלאה של שפות נתמכות וקודי ה־ISO שלהן ב־endpoint של רשימת כל שפות היעד. |
translations[].file |
file | כן | קובץ התרגום להעלאה. |
additional_translation_files |
array[object] | לא | הגדרות של קבצי פלט נוספים עבור פורמטים מסוימים. כדי לראות אילו פורמטים תומכים בקבצי פלט נוספים, עיינו ב־endpoint של רשימת פורמטי קבצים נתמכים. עבור פורמטים שאינם נתמכים, המערכת תתעלם משדה זה. |
additional_translation_files[].type |
string | כן | ראו פורמטים נתמכים של קבצים לפרטים נוספים. |
additional_translation_files[].path |
string | כן | תבנית הנתיב עבור הקובץ. |
תגובות
תגובת הצלחה
{
"source_file": {
"id": 123,
"file_path": "src/locales/en.json",
"created_at": "2024-01-15T10:30:00.000Z",
"file_tag": {
"id": 456,
"name": "frontend"
}
}
}סכמת תגובה
| שדה | סוג | תיאור |
|---|---|---|
source_file.id |
integer | המזהה הייחודי של קובץ המקור שנוצר. |
source_file.file_path |
string | הנתיב של קובץ המקור בתוך הפרויקט. |
source_file.created_at |
string | חותמת זמן בתקן ISO 8601 המציינת מתי קובץ המקור נוצר במקור. |
source_file.file_tag.id |
integer | מזהה תגית הקובץ. |
source_file.file_tag.name |
string | שם תגית הקובץ. |
תגובות שגיאה
האימות נכשל
{
"success": false,
"error": "Source file creation failed"
}לא מורשה (Unauthorized)
{
"error": "Unauthorized access. Please provide a valid API token."
}גישה נדחתה (Forbidden)
{
"error": "Access denied. Insufficient permissions."
}בקשות לדוגמה
יצירה בסיסית של קובץ מקור:
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"בקשה עם 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"בקשה עם תרגומים קיימים:
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"בקשה עם קבצי פלט נוספים:
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"דוגמאות קוד
- JavaScript (FormData)
- Python (requests)
- PHP (cURL)
- Node.js (axios)
- גוף בקשת Callback
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"
}עיבוד קובץ המקור
מעלה תוכן לקובץ מקור קיים ומתחיל את תהליך התרגום.
endpoint זה מחליף את התוכן הנוכחי של הקובץ, מעדכן את המחרוזות לתרגום השמורות, ומתחיל תרגום אוטומטי.
כדי להשתמש ב־endpoint זה, קובץ המקור חייב להיות קיים כבר בפרויקט. אם טרם יצרתם אותו, ראו יצירת קובץ המקור.
בקשת HTTP
PUT https://app.ptc.wpml.org/api/v1/source_files/processפרמטרים
| פרמטר | סוג | חובה | תיאור |
|---|---|---|---|
file |
file | כן | קובץ המקור להעלאה. תוכן הקובץ עובר אימות כדי להבטיח שהוא תואם לסיומת המוצהרת שלו. לדוגמה, אם סיומת הקובץ היא .json, התוכן המועלה חייב להיות JSON תקין. |
file_path |
string | כן | הנתיב לקובץ המקור הקיים בפרויקט שיש לעדכן. |
file_tag_name |
string | לא | שם תגית הקובץ המשויכת לקובץ המקור. אם לא סופק, נעשה שימוש בתגית ברירת המחדל של הפרויקט. |
callback_url |
string | לא | כתובת ה־URL שמקבלת התראות webhook כאשר עיבוד הקובץ מסתיים. |
תגובות
תגובת הצלחה
{
"source_file": {
"id": 123,
"file_path": "src/locales/en.json",
"created_at": "2024-01-15T10:30:00.000Z",
"file_tag": {
"id": 456,
"name": "frontend"
}
}
}סכמת תגובה
| שדה | סוג | תיאור |
|---|---|---|
source_file.id |
integer | המזהה הייחודי של קובץ המקור שעובד. |
source_file.file_path |
string | הנתיב של קובץ המקור בתוך הפרויקט. |
source_file.created_at |
string | חותמת זמן בתקן ISO 8601 המציינת מתי קובץ המקור נוצר במקור. |
source_file.file_tag.id |
integer | מזהה תגית הקובץ. |
source_file.file_tag.name |
string | שם תגית הקובץ. |
תגובות שגיאה
קובץ המקור לא נמצא
{
"errors": {
"file": ["File format is invalid or not supported"]
}
}לא מורשה (Unauthorized)
{
"error": "Unauthorized access. Please provide a valid API token."
}גישה נדחתה (Forbidden)
{
"error": "Access denied. Insufficient permissions."
}תהליך עבודה
- דרישת קדם: קובץ המקור חייב להיות קיים לאחר שנוצר דרך יצירת קובץ המקור.
- העלאת קובץ: תוכן חדש מועלה ומחליף את תוכן הקובץ הקיים.
- עיבוד: המחרוזות החדשות לתרגום מחולצות ומתורגמות אוטומטית.
- Callback: התראת webhook אופציונלית נשלחת כאשר העיבוד מסתיים.
Webhook Callback
כאשר מסופק callback_url, PTC תשלח בקשת POST לכתובת URL זו עם סיום העיבוד.
גוף בקשת ה־callback:
{
"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"
}בקשות לדוגמה
עיבוד קובץ בסיסי:
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"בקשה עם 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"דוגמאות קוד
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);פורמטים נתמכים של קבצים
ה־endpoint תומך במגוון פורמטים של קבצים לתרגום, כולל קובצי JSON, PO/POT, XLIFF ו־Properties, בין היתר. אימות פורמט הקובץ מתבצע במהלך ההעלאה כדי להבטיח תאימות.
השתמשו ב־endpoint פירוט פורמטי קבצים נתמכים כדי לקבל את הרשימה המלאה של הפורמטים הנתמכים.
קבלת סטטוס התרגום
מאחזר את התקדמות התרגום הנוכחית עבור קובץ מקור מסוים, כולל כמה ממנו הושלם וסטטוס העיבוד הכללי שלו.
זה שימושי עבור:
- מעקב התקדמות – מעקב אחר התקדמות התרגום עבור משימות ארוכות
- עדכוני ממשק משתמש – הצגת אחוזי השלמה באפליקציה שלכם
- אינטגרציה עם תהליכי עבודה – הפעלת פעולות כאשר התרגום מגיע לסף מוגדר
בקשת HTTP
GET https://app.ptc.wpml.org/api/v1/source_files/translation_statusפרמטרים
| פרמטר | סוג | חובה | תיאור |
|---|---|---|---|
file_path |
string | כן | הנתיב לקובץ המקור בתוך הפרויקט. |
file_tag_name |
string | לא | שם תגית הקובץ. אם לא סופק, נעשה שימוש בתגית ברירת המחדל של הפרויקט. |
תגובות
תגובת הצלחה
{
"translation_status": {
"status": "completed",
"completeness": 100
}
}סכמת תגובה
| שדה | סוג | תיאור |
|---|---|---|
translation_status.status |
string | סטטוס העיבוד הנוכחי של קובץ המקור. ראו ערכי סטטוס למטה. |
translation_status.completeness |
number | אחוז המחרוזות המתורגמות (0–100). מחושב בתור (completed_translatable_strings / total_translatable_strings) × 100. |
ערכי סטטוס
השדה status יכול להכיל את הערכים הבאים:
| סטטוס | תיאור |
|---|---|
pending |
קובץ המקור ממתין לעיבוד. |
processing |
התרגום מתבצע כעת. |
completed |
כל התרגומים הושלמו. |
failed |
תהליך התרגום נתקל בשגיאות. |
תגובות שגיאה
קובץ המקור לא נמצא
{
"error": "Source file not found"
}לא מורשה (Unauthorized)
{
"error": "Unauthorized access. Please provide a valid API token."
}גישה נדחתה (Forbidden)
{
"error": "Access denied. Insufficient permissions."
}פרמטרים לא תקינים
{
"error": "Invalid parameters provided."
}בקשות לדוגמה
בקשה בסיסית:
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"בקשה עם תגית קובץ:
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"דוגמאות קוד
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`);הורדת כל התרגומים
מוריד את כל הקבצים המתורגמים עבור קובץ מקור מסוים בתור קובץ ZIP.
endpoint זה יוצר ומחזיר קובץ ZIP המכיל את כל קבצי התרגום בשפות היעד עבור קובץ המקור שצוין.
אם אין תרגומים זמינים עבור הקובץ, הבקשה תחזיר שגיאת 404 Not Found.
בקשת HTTP
GET https://app.ptc.wpml.org/api/v1/source_files/download_translationsפרמטרים
| פרמטר | סוג | חובה | תיאור |
|---|---|---|---|
file_path |
string | כן | הנתיב לקובץ המקור בתוך הפרויקט. |
file_tag_name |
string | לא | שם תגית הקובץ. אם לא סופק, נעשה שימוש בתגית ברירת המחדל של הפרויקט. קובץ מקור מזוהה באופן ייחודי על ידי השילוב של file_path ו־file_tag_name. |
תגובות
תגובת הצלחה
{
"status": "processing",
"message": "Translations are still in progress. Please retry after the specified delay.",
"retry_after": 30
}PTC מעבדת תרגומים באופן אסינכרוני. בדרך כלל ישנה המתנה קצרה בין העלאת קובץ מקור לבין זמינות התרגומים להורדה.
כאשר זה קורה, המתינו את מספר השניות המצוין ב־Retry-After.
תגובות שגיאה
קובץ המקור לא נמצא
{
"error": "Source file not found"
}אין תרגומים זמינים
{
"error": "No translations are available for this source file"
}לא מורשה (Unauthorized)
{
"error": "Unauthorized access. Please provide a valid API token."
}גישה נדחתה (Forbidden)
{
"error": "Access denied. Insufficient permissions."
}פרמטרים לא תקינים
{
"error": "Invalid parameters provided."
}בקשות לדוגמה
בקשה בסיסית:
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.zipבקשה עם תגית קובץ:
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.zipדוגמאות קוד
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');
}העלאת קובצי מקור באצווה
מעלה קובץ ZIP המכיל מספר קבצים לתרגום. כל קובץ בארכיון מחולץ, עובר אימות ומעובד. פורמטים נתמכים מזוהים אוטומטית.
זוהי גרסת האצווה של עיבוד קובץ המקור, שנועדה להאיץ עדכונים בקנה מידה גדול.
מידע נוסף
- אם קובץ תואם לקובץ מקור קיים, הוא מעודכן בתוכן החדש, ותרגומים מופעלים מחדש.
- אם קובץ נתמך אך אינו תואם לאף קובץ מקור קיים, הוא מתווסף לרשימת
not_found_filesוהמערכת מתעלמת ממנו. - קבצים בעלי פורמטים שאינם נתמכים מפורטים תחת
unsupported_filesוהמערכת מתעלמת מהם. - קבצים עם תוכן לא תקין מפורטים גם הם תחת
unsupported_filesוהמערכת מתעלמת מהם. - עיבוד של ארכיונים גדולים עשוי להימשך זמן רב יותר. קבצים מעובדים אחד-אחד כדי לנהל משאבים, ולכן מומלץ לפצל העלאות גדולות מאוד (יותר מ־100 קבצים) לאצוות קטנות יותר. כל הקבצים בארכיון מוגדרים לתרגום אוטומטי.
- קובץ ה־ZIP המועלה חייב להיות תקין וקריא. כל הקבצים בתוכו חייבים להיות בפורמט נתמך. שמות קבצים לא צריכים לכלול תווים מיוחדים שעלולים לגרום לבעיות נתיב.
- אם מסופק
callback_url, נשלחת בקשתPOSTעבור כל קובץ מקור שעובד, יחד עם התוצאות שלו.
בקשת HTTP
POST https://app.ptc.wpml.org/api/v1/source_files/bulkפרמטרים
| פרמטר | סוג | חובה | תיאור |
|---|---|---|---|
zip_file |
file | כן | קובץ ZIP המכיל את קובצי המקור להעלאה. חייב להיות קובץ ZIP תקין. |
file_tag_name |
string | לא | שם תגית הקובץ שתשויך לכל קובצי המקור בארכיון. אם לא צוין, נעשה שימוש בתגית ברירת המחדל של הפרויקט. כל קובץ מקור מזוהה באופן ייחודי על ידי השילוב של file_path ו־file_tag_name. |
callback_url |
string | לא | כתובת ה־URL שמקבלת התראות webhook כאשר כל קובץ מעובד. |
מבנה צפוי לקובץ ה־ZIP
קובץ ה־ZIP יכול להכיל קובצי מקור בכל מבנה ספריות שהוא. מבנה הספריות נשמר, והקבצים מעובדים באופן רקורסיבי.
מבנה לדוגמה של קובץ ZIP:
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)
סוגי קבצים נתמכים:
- JSON: קובצי
.json - Gettext: קובצי
.po,.pot - Properties: קובצי
.properties - YAML: קובצי
.yml,.yaml - XML: קובצי
.xml - Strings: קובצי
.strings - XLIFF: קובצי
.xliff,.xlf - CSV: קובצי
.csv - PHP: קובצי
.php
תגובות
תגובת הצלחה
{
"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"]
}סכמת תגובה
| שדה | סוג | תיאור |
|---|---|---|
success |
boolean | האם פעולת העלאת האצווה הצליחה. |
file_tag |
object | מידע אודות תגית הקובץ. |
file_tag.id |
integer | מזהה תגית הקובץ. |
file_tag.name |
string | שם תגית הקובץ. |
processed_files |
array[object] | מערך של קובצי מקור שעובדו בהצלחה. |
processed_files[].id |
integer | המזהה הייחודי של קובץ המקור שנוצר. |
processed_files[].file_path |
string | הנתיב של קובץ המקור, תוך שמירה על מבנה ה־ZIP המקורי. |
processed_files[].created_at |
string | חותמת זמן בתקן ISO 8601 המציינת מתי קובץ המקור נוצר. |
processed_files[].file_tag |
object | מידע אודות תגית הקובץ. |
processed_files[].file_tag.id |
integer | מזהה תגית הקובץ. |
processed_files[].file_tag.name |
string | שם תגית הקובץ. |
unsupported_files |
array[string] | מערך של שמות קבצים שאינם בפורמט נתמך. |
not_found_files |
array[string] | מערך של קבצים נתמכים שלא תאמו לאף קובץ מקור קיים והמערכת התעלמה מהם. |
תגובות שגיאה
קובץ ZIP לא תקין
{
"success": false,
"error": "File format is invalid",
"processed_files": [],
"unsupported_files": []
}העיבוד נכשל
{
"success": false,
"error": "Failed to process ZIP archive",
"processed_files": [],
"unsupported_files": []
}לא מורשה (Unauthorized)
{
"error": "Unauthorized access. Please provide a valid API token."
}גישה נדחתה (Forbidden)
{
"error": "Access denied. Insufficient permissions."
}Webhook Callback
כאשר מסופק callback_url, נשלחת בקשת POST עבור כל קובץ שעובד.
גוף בקשת ה־callback (לכל קובץ):
{
"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"
}בקשות לדוגמה
העלאת אצווה בסיסית:
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"בקשה עם 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"דוגמאות קוד
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);