Dogfennaeth API
Cyfuno cyfieithiad pwerus i'ch cymhwysiadau gyda'n API REST syml.
Cychwyn
Mae'r TranslateAPI yn darparu rhyngwyneb REST syml ar gyfer cyfieithu testun rhwng 180+ o ieithoedd. Mae pob diwedd-bwynt API yn dychwelyd ymatebion JSON.
https://api.translateapi.ai/api/v1/
Cychwyn Cyflym
Gwneud eich cais cyfieithiad cyntaf:
curl -X POST https://api.translateapi.ai/api/v1/translate/ \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{
"text": "Hello, world!",
"target_language": "es"
}'
import requests
response = requests.post(
"https://api.translateapi.ai/api/v1/translate/",
headers={
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
json={
"text": "Hello, world!",
"target_language": "es"
}
)
result = response.json()
print(result["translated_text"]) # "Hola, mundo!"
const response = await fetch("https://api.translateapi.ai/api/v1/translate/", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
text: "Hello, world!",
target_language: "es"
})
});
const result = await response.json();
console.log(result.translated_text); // "Hola, mundo!"
using System;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
class Program
{
static async Task Main()
{
var client = new HttpClient();
client.DefaultRequestHeaders.Add(
"Authorization", "Bearer YOUR_API_KEY"
);
var content = new StringContent(
JsonConvert.SerializeObject(new {
text = "Hello, world!",
target_language = "es"
}),
Encoding.UTF8,
"application/json"
);
var response = await client.PostAsync(
"https://api.translateapi.ai/api/v1/translate/",
content
);
var result = await response.Content.ReadAsStringAsync();
var data = JsonConvert.DeserializeObject<dynamic>(result);
Console.WriteLine(data.translated_text); // "Hola, mundo!"
}
}
Dilysiant
Dilysu eich ceisiadau gan ddefnyddio allwedd API. Gallwch greu allweddi API o'ch Dashboard.
Dilysiant Pennawd (Argymhellir)
Authorization: Bearer ta_your_api_key_here
Paramedrau Ymholiad
https://api.translateapi.ai/api/v1/translate/?api_key=ta_your_api_key_here
Cyfieithu Testun
Cyfieithu testun i iaith targed sengl.
POST https://api.translateapi.ai/api/v1/translate/
Corff y Cais
| Paramedrau | Math | Angenrheidiol | Disgrifiad |
|---|---|---|---|
text |
string | _Yw | Testun i' w gyfieithu (uchafswm o 50,000 o nodau) |
target_language |
string | Ie* | Target language code (e.g., "es", "fr", "de") |
source_language |
string | _Na | Source language code. Default: "auto" (auto-detect) |
* Defnyddio target_language (string) ar gyfer iaith sengl neu target_languages (arae) ar gyfer lluosog. Gweler Cyfieithiad Aml- Targed.
Ymateb
{
"translated_text": "Hola, mundo!",
"source_language": "en",
"target_language": "es",
"translations": {
"es": "Hola, mundo!"
},
"character_count": 13,
"translation_time": 0.45
}
Cyfieithiad Aml- Targed
Cyfieithu testun i ieithoedd lluosol mewn cais unigol. Defnyddia' r un diwedd- pwynt â chyfieithiad unigol.
POST https://api.translateapi.ai/api/v1/translate/
Corff y Cais
{
"text": "Hello, world!",
"target_languages": ["es", "fr", "de", "ja"],
"source_language": "en"
}
Defnyddio target_languages (arae) yn lle target_language (string) ar gyfer nifer o dargedau.
Ymateb
{
"source_language": "en",
"translations": {
"es": "Hola, mundo!",
"fr": "Bonjour, monde!",
"de": "Hallo, Welt!",
"ja": "こんにちは、世界!"
},
"character_count": 52,
"translation_time": 2.31
}
Cyfieithiad
Cyfieithu testunau lluosol ar yr un pryd gyda phrosesu asyncronig. Anfon batch a pleidleisio am ganlyniadau.
POST https://api.translateapi.ai/api/v1/translate/batch/
Cam 1: Anfon Batch
curl -X POST https://api.translateapi.ai/api/v1/translate/batch/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"texts": ["Hello", "Goodbye", "Thank you"],
"target_language": "es",
"source_language": "en"
}'
Ymateb (Cedwir HTTP 202)
{
"job_id": "67535b2b-c9e3-4f82-9499-e237edbc1dd8",
"status": "pending",
"total_texts": 3,
"queue_position": 1,
"source_language": "en",
"target_languages": ["es"],
"character_count": 22,
"credits_remaining": -1,
"poll_url": "https://api.translateapi.ai/api/v1/jobs/67535b2b-c9e3-4f82-9499-e237edbc1dd8/"
}
Cam 2: Pleidleisio am ganlyniadau
GET https://api.translateapi.ai/api/v1/jobs/{job_id}/
Enghraifft o bleidleisio (Python)
import time, requests
job_id = response.json()["job_id"]
total = response.json()["total_texts"]
headers = {"Authorization": "Bearer YOUR_API_KEY"}
print(f"Batch submitted: {total} texts (job {job_id})")
while True:
result = requests.get(f"https://api.translateapi.ai/api/v1/jobs/{job_id}/", headers=headers).json()
status = result["status"]
processed = result.get("processed_texts", 0)
progress = result.get("progress_percentage", 0)
if status == "completed":
print(f"Completed: {processed}/{total} texts in {result.get('processing_time', 0):.1f}s")
translations = result["result_data"]["translations"]
break
elif status == "failed":
print(f"Failed at {processed}/{total}: {result.get('error_message', 'unknown')}")
raise Exception(result.get("error_message", "Translation failed"))
elif status == "pending":
queue_pos = result.get("queue_position", "?")
print(f"Queued (position {queue_pos}) — waiting for GPU worker...")
else:
print(f"[{status}] {processed}/{total} ({progress:.0f}%)")
time.sleep(3)
Ymateb (ar y gweill - yn y rhes, yn aros am GPU)
{
"job_id": "67535b2b-...",
"status": "pending",
"processed_texts": 0,
"total_texts": 3,
"progress_percentage": 0.0,
"queue_position": 3
}
Ymateb (yn y broses)
{
"job_id": "67535b2b-...",
"status": "processing",
"processed_texts": 1,
"total_texts": 3,
"progress_percentage": 33.33,
"queue_position": null
}
Ymateb (wedi cwblhau)
{
"job_id": "67535b2b-...",
"status": "completed",
"processed_texts": 3,
"total_texts": 3,
"progress_percentage": 100.0,
"processing_time": 10.65,
"result_data": {
"translations": ["Hola", "Adiós", "Gracias"],
"source_language": "en",
"target_language": "es",
"character_count": 22,
"processing_time": 10.65
}
}
Trosolwg Cynnydd Amser Real
Mae pob ymateb pleidlais yn cynnwys meysydd cynnydd amser real fel y gallwch fonitro'n union beth sy'n digwydd gyda'ch batch:
| Maes | Disgrifiad |
|---|---|
status |
Cyflwr y swydd gyfredol: pending (mewn rhes, yn aros am weithiwr GPU), processing (yn cyfieithu' n weithredol), completed, failed |
processed_texts |
Nifer o gyfieithiadau unigol wedi' u cwblhau hyd yma. Diweddariadau mewn amser real wrth i bob testun gael ei gyfieithu. |
total_texts |
Cyfanswm nifer y cyfieithiadau yn y batch yma (testunau × ieithoedd cyrchfan). |
progress_percentage |
Canran gwblhau (0-100). Cyfrifir o processed_texts / total_texts. |
queue_position |
Eich safle yn y ciw pan fo'r cyflwr yn "ar y gweill" (1 = nesaf i fyny). Null pan yn cael ei brosesu neu wedi gorffen. Defnyddiwch hyn i amcangyfrif amser aros a dangos cyflwr y ciw i'ch defnyddwyr. |
processing_time |
Cyfanswm amser prosesu mewn eiliadau (ar gael pan yn gwblhau). |
status yw "pending", mae' r gweithwyr GPU yn brysur efo batiau eraill. Gwirio queue_position i weld faint o swyddi sydd o flaen eich swydd chi (1 = chi yw'r nesaf). Dechreuir eich swydd yn ymysgogol — nid oes angen unrhyw weithred, dim ond cadw'n pobi.
Ymarfer Gorau ar gyfer Gweithlwythau Mawr
- Anfon 1 iaith cyrchfan am bob cais batch. Mae hyn yn cadw pob batch yn gyflym ac yn gwneud dilyn cynnydd yn hawdd.
- Cadw bandiau o 50- 100 testun. Mae bandiau llai yn cwblhau' n gyflymach ac yn rhoi diweddariadau cynnydd mwy aml i chi.
- Rhedeg hyd at 2 swydd batch gyd-destunol. Mae'r GPU yn prosesu 2 batch yn gyd-destunol — mae swyddi ychwanegol yn y rhes ac ni fyddant yn dechrau'n gyflymach.
- Pan ddaw'r amser i ben, ail-brofi'r un job_id yn hytrach na chyflwyno batch newydd. Gall y swydd wreiddiol fod yn cael ei phrosesu ar y GPU.
- Pleidleisio bob 3- 5 eiliad. Nid yw pleidleisio' n fwy aml yn cyflymu prosesu.
Batch Aml- Iaith
Cyfieithu testunau lluosol i nifer o ieithoedd ar yr un pryd:
{
"texts": ["Hello", "Goodbye"],
"target_languages": ["es", "fr"],
"source_language": "en"
}
_Data canlyniad wedi'i gwblhau
{
"translations": [
{"es": "Hola", "fr": "Bonjour"},
{"es": "Adiós", "fr": "Au revoir"}
],
"source_language": "en",
"target_languages": ["es", "fr"],
"character_count": 24,
"processing_time": 2.45
}
Paramedrau Cais
| Paramedrau | Math | Angenrheidiol | Disgrifiad |
|---|---|---|---|
texts |
array | _Yw | Array o linynnau i gyfieithu |
target_language |
string | Ie* | Côd iaith cyrchfan ar gyfer iaith sengl |
target_languages |
array | Ie* | Array o godau iaith cyrchfan ar gyfer nifer o ieithoedd |
source_language |
string | _Na | Source language code. Default: "auto" |
* Rhowch naill ai target_language neu target_languages, nid y ddau.
job_id. Twll GET /api/v1/jobs/{job_id}/ hyd status yw "completed", wedyn darllen result_data Defnyddio progress_percentage i olrhain cynnydd.
Cyfieithiad Dogfen
Cyfieithu dogfennau cyfan tra' n cadw fformatio. Cynhelir fformatau ffeil lluosol.
POST https://api.translateapi.ai/api/v1/translate/document/
Cais (data aml-ran/forma)
| Paramedrau | Math | Angenrheidiol | Disgrifiad |
|---|---|---|---|
file |
file | _Yw | Y ddogfen i gyfieithu (uchafswm 10MB) |
target_language |
string | _Yw | Target language code (e.g., "es", "fr", "de") |
source_language |
string | _Na | Source language code. Default: "auto" (auto-detect) |
Mathau Ffeil a Gynhelir
.txt- Ffeiliau testun plaen.docx- Dogfennau Word.pdf- Dogfennau PDF (gan gynnwys rhai wedi'u sganio).json- Ffeiliau JSON (yn cyfieithu gwerthoedd llinyn).xml- Ffeil XML
.srt- Ffeiliau isdeitlau.po/.pot- Ffeiliau cyfieithiad Gettext.jpg/.jpeg- Delwedd JPEG.png- Delwedd PNG.tiff/.tif- Delwedd TIFF.bmp- Delweddau BMP.webp- Delwedd WebP
Enghraifft (cURL)
# Translate a Word document
curl -X POST https://api.translateapi.ai/api/v1/translate/document/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@document.docx" \
-F "target_language=es" \
-F "source_language=en"
# Translate text from an image (OCR)
curl -X POST https://api.translateapi.ai/api/v1/translate/document/ \
-H "Authorization: Bearer YOUR_API_KEY" \
-F "file=@scanned_page.jpg" \
-F "target_language=es" \
-F "source_language=en"
.txt ffeil.
Ymateb
{
"id": 123,
"original_filename": "document.docx",
"file_type": "docx",
"source_language": "en",
"target_language": "es",
"status": "completed",
"character_count": 5420,
"translated_file_url": "/media/translated/document_es.docx",
"created_at": "2024-01-15T10:30:00Z",
"completed_at": "2024-01-15T10:30:05Z"
}
Gwerthoedd Cyflwr
pending |
Ffeil wedi' i lanlwytho, yn aros i' w phrosesu |
processing |
Cyfieithiad ar waith |
completed |
Cyfieithiad wedi gorffen, lawrlwythiad ar gael |
failed |
Methodd y cyfieithiad (gweler error_message) |
GET https://api.translateapi.ai/api/v1/translate/document/{id}/
Gwirio cyflwr cyfieithiad dogfen neu nôl URL y lawrlwythiad.
Ymateb
{
"id": 123,
"original_filename": "document.docx",
"status": "completed",
"translated_file_url": "/media/translated/document_es.docx",
"character_count": 5420
}
Canfod Iaith
Mae canfod iaith yn cael ei fewnosod i bob cais cyfieithiad. Set source_language to "auto" (neu ei hepgor) a dychwelir yr iaith a ganfuwyd yn yr ymateb.
POST https://api.translateapi.ai/api/v1/translate/
Corff y Cais
{
"text": "Bonjour, comment allez-vous?",
"target_language": "en"
}
Ymateb
{
"translated_text": "Hello, how are you?",
"source_language": "fr",
"target_language": "en",
"translations": {
"en": "Hello, how are you?"
},
"character_count": 28,
"translation_time": 0.52
}
Y source_language Mae' r maes yn yr ymateb yn dangos yr iaith a ganfuwyd pan ddefnyddir canfod yn awtomatig.
Ieithoedd a gynhelir
Nôl y rhestr o holl ieithoedd a gynhelir.
GET https://api.translateapi.ai/api/v1/translate/languages/
Ymateb
{
"count": 186,
"results": [
{"iso": "en", "name": "English", "en_label": "English"},
{"iso": "es", "name": "Español", "en_label": "Spanish"},
{"iso": "fr", "name": "Français", "en_label": "French"},
...
]
}
Modelau Cyfieithu
Rydym yn defnyddio modelau cyfieithu ffynhonnell agored o'r radd flaenaf sy'n rhedeg ar ein strwythur GPU ein hunain. Mae pob model wedi'i drwyddedu'n fasnachol (Apache 2.0).
| Model | Ieithoedd | Gorau ar gyfer |
|---|---|---|
| Helsinki-NLP/opus-mt | 50+ pâr iaith | Ieithoedd cyffredin (EN, ES, FR, DE, IT, PT, RU, ZH, JA, ac ati) |
| Google MADLAD-400 | 400+ iaith | Ieithoedd annisgwyl, cwmpasu eang |
Mae'r API yn dewis yn ymysgogol y model gorau ar gyfer eich pâr iaith. Gallwch benodi un yn ddewisol engine paramedr:
| Peiriant | Disgrifiad |
|---|---|
"auto" |
Rhagosodedig. Ceisio HuggingFace yn gyntaf, yna dychwelyd i MADLAD-400 |
"huggingface" |
Gorfodi HuggingFace/MarianMT (y cyflymaf, 50+ iaith) |
"madlad" |
Force MADLAD-400 (400+ iaith) |
Triniaeth Gwallau
Mae'r API yn defnyddio codau cyflwr HTTP safonol i ddangos llwyddiant neu fethiant.
| Côd | Disgrifiad |
|---|---|
200 |
Llwyddiant |
400 |
Cais drwg - Paramedrau annilys |
401 |
Heb ei awdurdodi - Allwedd API annilys neu ar goll |
402 |
Angen talu - Cyfanswm nodau diwrnod wedi' u hennill |
429 |
Gormod o Geisiadau - Terfyn Cyflymder wedi' i Derfynu |
503 |
Gwasanaeth ddim ar gael - peiriant cyfieithu dros dro i lawr |
Fformat Ymateb Gwall
{
"error": "daily_limit_exceeded",
"credits_remaining": 0,
"daily_limit": 100000
}
Terfynau Cyfradd
Mae terfynau'n amrywio yn ôl y cynllun. Gweler prisio am fanylion llawn:
| Cynllun | Nodau/Mis | Prisiau | |
|---|---|---|---|
| Rhydd | 250,000 | $0 | Cofrestru |
| Cychwynydd | 2,500,000 | $9/% 1 mis | Tanysgrifio |
| Pro | 10,000,000 | $29/% 1 mis | Tanysgrifio |
| Busnes | 40,000,000 | $79/% 1 mis | Tanysgrifio |
| Graddio | 125,000,000 | $199/% 1 mis | Tanysgrifio |
Pan fyddwch yn mynd dros eich terfyn, byddwch yn derbyn 429 Too Many Requests hyd y mis nesaf neu nes i chi uwchraddio.
Cwmwl
Mae TranslateAPI yn rhedeg ar enghreifftiau GPU NVIDIA A100 wedi'u dyrannu gyda graddnodi llorweddol ymysgogol. Pan mae'r galw yn cynyddu, lansiir enghreifftiau GPU ychwanegol o fewn munudau i gadw amserau ymateb cyflym. Mae hyn yn golygu y gall ein API drin ceisiadau cydweithredol bron heb gyfyngiad heb ddirywio - o gais sengl i filoedd y funud.