title: Translate description: Translate text from a source language to a target language using the v1 API
Translate (v1)
Translate text from a source language to a target language using the v1 API.
Endpoint
POST /v1/translate
Description
Translate text from a source language to a target language using the v1 API.
Headers
X-API-KEY string (required)
: Your API key for authentication
Content-Type string (required)
: Must be application/json
Request Parameters
Body Parameters
text string (required)
: The text to translate
source string (required)
: Source language code (e.g., "en", "fr")
target string (required)
: Target language code (e.g., "en", "fr")
Example Request
curl https://api.translateplus.io/v1/translate \
-H "X-API-KEY: your_api_key" \
-H "Content-Type: application/json" \
-d '{
"text": "Hello, world!",
"source": "en",
"target": "fr"
}'
import requests
url = "https://api.translateplus.io/v1/translate"
headers = {
"X-API-KEY": "your_api_key",
"Content-Type": "application/json"
}
data = {
"text": "Hello, world!",
"source": "en",
"target": "fr"
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
fetch('https://api.translateplus.io/v1/translate', {
method: 'POST',
headers: {
'X-API-KEY': 'your_api_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
text: 'Hello, world!',
source: 'en',
target: 'fr'
})
})
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));
const https = require('https');
const data = JSON.stringify({
text: 'Hello, world!',
source: 'en',
target: 'fr'
});
const options = {
hostname: new URL('https://api.translateplus.io').hostname,
path: '/v1/translate',
method: 'POST',
headers: {
'X-API-KEY': 'your_api_key',
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = https.request(options, (res) => {
let responseData = '';
res.on('data', (chunk) => {
responseData += chunk;
});
res.on('end', () => {
console.log(JSON.parse(responseData));
});
});
req.on('error', (error) => {
console.error('Error:', error);
});
req.write(data);
req.end();
<?php
$url = 'https://api.translateplus.io/v1/translate';
$apiKey = 'your_api_key';
$data = [
'text' => 'Hello, world!',
'source' => 'en',
'target' => 'fr'
];
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'X-API-KEY: ' . $apiKey,
'Content-Type: application/json'
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 200) {
$result = json_decode($response, true);
echo $result['translation'];
} else {
echo 'Error: ' . $response;
}
Success Response (200 OK)
{
"translation": "Bonjour le monde!",
"source": "en",
"target": "fr"
}
Response Fields
| Field | Type | Description |
|-------|------|-------------|
| translation | string | The translated text |
| source | string | Source language code |
| target | string | Target language code |
Error Responses
See Error Handling for common error responses.
Migration to v2
We recommend migrating to the v2 Translate endpoint which provides enhanced features and better error handling.