title: Translate HTML description: Translate HTML content while preserving all tags, attributes, and document structure
Translate HTML
Translate HTML content while preserving all tags, attributes, and document structure.
Endpoint
POST /v2/translate/html
Script and style tags are automatically skipped and not translated. All HTML tags, attributes, and structure are preserved exactly as provided.
Headers
X-API-KEY string (required)
: Your API key for authentication
Content-Type string (required)
: Must be application/json
Request Parameters
Body Parameters
html string (required)
: The HTML content to translate (1-50000 characters)
source string (required)
: Source language code (e.g., "en", "fr") or "auto" for auto-detection
target string (required)
: Target language code (e.g., "en", "fr")
Example Request
curl https://api.translateplus.io/v2/translate/html \
-H "X-API-KEY: your_api_key" \
-H "Content-Type: application/json" \
-d '{
"html": "<p>Hello <b>world</b>! This is a <span>test</span>.</p><p>Line two: <i>How are you?</i></p>",
"source": "en",
"target": "fr"
}'
import requests
url = "https://api.translateplus.io/v2/translate/html"
headers = {
"X-API-KEY": "your_api_key",
"Content-Type": "application/json"
}
data = {
"html": "<p>Hello <b>world</b>! This is a <span>test</span>.</p><p>Line two: <i>How are you?</i></p>",
"source": "en",
"target": "fr"
}
response = requests.post(url, json=data, headers=headers)
print(response.json())
fetch('https://api.translateplus.io/v2/translate/html', {
method: 'POST',
headers: {
'X-API-KEY': 'your_api_key',
'Content-Type': 'application/json'
},
body: JSON.stringify({
html: '<p>Hello <b>world</b>! This is a <span>test</span>.</p><p>Line two: <i>How are you?</i></p>',
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({
html: '<p>Hello <b>world</b>! This is a <span>test</span>.</p><p>Line two: <i>How are you?</i></p>',
source: 'en',
target: 'fr'
});
const options = {
hostname: new URL('https://api.translateplus.io').hostname,
path: '/v2/translate/html',
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/v2/translate/html';
$apiKey = 'your_api_key';
$data = [
'html' => '<p>Hello <b>world</b>! This is a <span>test</span>.</p><p>Line two: <i>How are you?</i></p>',
'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['html'];
} else {
echo 'Error: ' . $response;
}
Success Response (200 OK)
{
"html": "<p>Bonjour <b>monde</b> ! C'est un <span>test</span>.</p><p>Ligne deux : <i>Comment allez-vous ?</i></p>"
}
Response Fields
| Field | Type | Description |
|-------|------|-------------|
| html | string | The translated HTML content with all tags preserved |
Features
- Tag Preservation: All HTML tags and attributes are preserved exactly as provided
- Structure Maintenance: Document structure and nesting are maintained
- Script & Style Skipping: Content inside
<script>and<style>tags is not translated - Nested Tags: Handles complex nested HTML structures correctly
- HTML Entities: Properly handles HTML entities and special characters
Error Responses
400 Bad Request
Invalid request parameters:
{
"detail": "Invalid language code 'xx'. Supported codes: en, fr, es..."
}
402 Payment Required
Insufficient credits:
{
"detail": "Insufficient credits. You have 0 credit(s) remaining, but this request requires 1 credit(s). Please upgrade your plan to continue using the API."
}
403 Forbidden
Invalid or missing API key:
{
"detail": "API key is required. Please provide X-API-KEY header."
}
429 Too Many Requests
Rate limit exceeded:
{
"detail": "Rate limit exceeded. You have made 60 requests. Maximum allowed: 60 requests per minute. Please try again after 45 seconds."
}
Credits
This endpoint requires 1 credit per request.