🌍 Multilingual Translation 🆕
🌍 Multilingual Translation API
Fast and accurate translation between 28 languages, optimized for long texts and high performance. Supports both single and batch translation.
Try Demo
🚀 Features
-
28 Languages:
ar,bn,cs,de,en,es,fa,fr,he,hi,id,it,ja,km,ko,lo,ms,my,nl,pl,pt,ru,th,tl,tr,ur,vi,zh -
Single & Batch Endpoints
-
Unlimited Text Support – Automatic chunking at sentence level
-
High Accuracy – Evaluated with BERTScore on real-world datasets
📈 Performance Benchmark (Thai → English)
Tested on 133,330 sentence pairs from the SCB MT En-TH 2020 dataset.
| Mode | Avg Time / 100 Sentences |
|---|---|
| 🧠 Batch | 18.06 sec |
| 🐌 Single | 30.54 sec |
💡 Tip: Use the batch API for best performance.
🧪 Quality (BERTScore)
Semantic similarity score between prediction and reference (1.0 = perfect match)
| Source → Target | BERTScore Mean |
|---|---|
| EN → MY | 0.9561 |
| EN → TH | 0.9506 |
| EN → JA | 0.9169 |
| JA → EN | 0.9146 |
| TH → EN | 0.8728 |
| TH → MY | 0.8571 |
| ZH → EN | 0.8571 |
✅ All tested pairs scored > 0.80
📡 API Endpoints
🔹 Single Translation
POST /v1/text/translate
Content-Type: application/x-www-form-urlencoded
Params:
text: Text to translatesource_lang: Source language code (e.g.en)target_lang: Target language code (e.g.th)max_length: (optional) Max output tokens
Example:
curl -X POST "https://api.iapp.co.th/v1/text/translate" \
-H "apikey: YOUR_API_KEY" \
-F "text=Hello" \
-F "source_lang=en" \
-F "target_lang=th"
Response:
{
"translation": "สวัสดี",
"processing_time": 0.056
}
🔹 Batch Translation
POST /v1/text/batch_translate
Content-Type: application/json
Body:
[
{
"text": "Hello",
"source_lang": "en",
"target_lang": "fr"
},
{
"text": "こんにちは",
"source_lang": "ja",
"target_lang": "en"
}
]
Response:
{
"results": [
{ "translation": "Bonjour", "index": 0 },
{ "translation": "Hello", "index": 1 }
]
}
🐍 Python Code Example
import requests
def translate_text(text, source_lang, target_lang, api_key, api_url="https://api.iapp.co.th"):
"""
Translate text using the Translation API
Args:
text (str): Text to translate
source_lang (str): Source language code (e.g., 'en', 'th', 'zh')
target_lang (str): Target language code (e.g., 'en', 'th', 'zh')
api_key (str): Your API key
api_url (str): Base URL of the API
Returns:
dict: Translation response
"""
data = {
"text": text,
"source_lang": source_lang,
"target_lang": target_lang
}
headers = {
"apikey": api_key
}
response = requests.post(f"{api_url}/v1/text/translate", data=data, headers=headers)
response.raise_for_status() # Raise exception for HTTP errors
return response.json()
# Example usage:
# result = translate_text("Hello", "en", "th", api_key="YOUR_API_KEY")
# print(result["translation"])
✅ This code uses application/x-www-form-urlencoded format, consistent with the API spec.
⚠️ Errors
| Code | Description |
|---|---|
| 400 | Invalid request |
| 401 | Missing or invalid API key |
| 429 | Rate limit exceeded |
| 500 | Internal server error |
| 503 | Service not ready |
✅ Summary
- 🏁 Fast & accurate for 28 languages
- 📄 Handles long text automatically
- 🧪 Proven high-quality translations
- 📦 Use batch mode for best speed