Documentation
API
Translation API
The Translation API is composed of 2 endpoints:
- Show Translation — show a translation
- Create Translation — create a translation
Show Translation
This endpoint is accessible by the read-only and read-write Project API key and is used to show a string.
/api/projects/:project_token/strings/:string_id/locales/:locale_code/translations.format [GET]
Where format is one of xml, json or yaml.
/api/projects/:project_token/strings/:string_id/locales/:locale_code/translations.jsoncurl "https://webtranslateit.com/api/projects/PROJECT_TOKEN/strings/1234/locales/fr/translations.json"
const response = await fetch(
'https://webtranslateit.com/api/projects/PROJECT_TOKEN/strings/1234/locales/fr/translations.json'
)
const translation = await response.json()
import requests
response = requests.get(
"https://webtranslateit.com/api/projects/PROJECT_TOKEN"
"/strings/1234/locales/fr/translations.json"
)
translation = response.json()
require 'net/http'
require 'json'
uri = URI('https://webtranslateit.com/api/projects/PROJECT_TOKEN/strings/1234/locales/fr/translations.json')
translation = JSON.parse(Net::HTTP.get(uri))
<?php
$ch = curl_init('https://webtranslateit.com/api/projects/PROJECT_TOKEN/strings/1234/locales/fr/translations.json');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$translation = json_decode(curl_exec($ch), true);
curl_close($ch);
Example response with JSON:
{
"id": 564959,
"locale": "fr",
"text": "Cet utilisateur a déjà été invité",
"status": "status_proofread",
"created_at": "2010-02-11 21:14:19 UTC",
"updated_at": "2011-10-09 08:33:18 UTC",
"version": 11,
"string": {
"id": 140067,
"key": "activerecord.errors.models.invitation.attributes.email.user_already_invited",
"plural": false,
"type": "String",
"dev_comment": null,
"status": "Current"
}
}
text: The actual translation.status: Translation status. One ofstatus_proofread,status_untranslated,status_unverified,status_unproofread,status_hidden(status from string),status_obsolete(status from string).version: Version number of the translation.- Some information from the string are returned as a convenience.
Create Translation
This endpoint is only accessible by the read-write Project API key and is used to create a new translation.
/api/projects/:project_token/strings/:string_id/locales/:locale_code/translations [POST]
Parameters
A JSON object modelled after the following:
{
"text": "Cet utilisateur a déjà été invité",
"status": "status_proofread",
"minor_change": "true"
}
All fields are optional. If no text is provided, WebTranslateIt will create an empty translation. Setting minor_change to true to a translation in source language won’t flag the target translations as “to verify”.
status can be one of status_proofread (proofread), status_unverified (to verify) or status_unproofread (to proofread). For more information on the string statuses, check String.
Note that you can also pass a validation parameter set to "false" if you don’t want translation validations to take place.
{
"text": "Cet utilisateur a déjà été invité",
"status": "status_proofread",
"validation": "false"
}
If everything goes well, WebTranslateIt will respond with 202 Created in the header and a JSON representation of the string just created in the body.
Note that updating an existing string is made using this same API, WebTranslateIt creates new versions of that translation.
If the translation cannot be saved due to a validation error, you will get a 406 response status with the following payload:
{
"error": "Error saving translation",
"description": "Validation check failed: the original text does not contain variables, so no variable should be included.",
"request": "https://webtranslateit.com/api/projects/:api_token/strings/:string_id/locales/fr/translations"
}
/api/projects/:project_token/strings/:string_id/locales/:locale_code/translationscurl -X POST "https://webtranslateit.com/api/projects/PROJECT_TOKEN/strings/1234/locales/fr/translations" \
-H "Content-Type: application/json" \
-d '{
"text": "Cet utilisateur a déjà été invité",
"status": "status_proofread"
}'
const response = await fetch(
'https://webtranslateit.com/api/projects/PROJECT_TOKEN/strings/1234/locales/fr/translations',
{
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
text: 'Cet utilisateur a déjà été invité',
status: 'status_proofread'
})
}
)
const translation = await response.json()
import requests
response = requests.post(
"https://webtranslateit.com/api/projects/PROJECT_TOKEN"
"/strings/1234/locales/fr/translations",
json={
"text": "Cet utilisateur a déjà été invité",
"status": "status_proofread",
},
)
translation = response.json()
require 'net/http'
require 'json'
uri = URI('https://webtranslateit.com/api/projects/PROJECT_TOKEN/strings/1234/locales/fr/translations')
response = Net::HTTP.post(uri, {
text: 'Cet utilisateur a déjà été invité',
status: 'status_proofread'
}.to_json, 'Content-Type' => 'application/json')
translation = JSON.parse(response.body)
<?php
$ch = curl_init('https://webtranslateit.com/api/projects/PROJECT_TOKEN/strings/1234/locales/fr/translations');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([
'text' => 'Cet utilisateur a déjà été invité',
'status' => 'status_proofread',
]));
$translation = json_decode(curl_exec($ch), true);
curl_close($ch);