Translation API

The Translation API is composed of 2 endpoints:

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.

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 of status_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.

Example Implementation in Ruby

require "net/http"
http = Net::HTTP.new("webtranslateit.com", 443)
request = Net::HTTP::Post.new("/api/projects/:api_token/strings/:string_id/locales/fr/translations")
http.request(request)

Example Implementation in PHP

<?php
  $api_key = "sekret";
  $string_id = "1234";
  $locale_code = "fr";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_URL, "https://webtranslateit.com/api/projects/" . $api_key . "/strings/". $string_id . "/locales/" . $locale_code . "/translations.json");
  $response = curl_exec($ch);
  $p = json_decode($response, true);
  print_r($p);
  curl_close($ch);
?>

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"
}

Example Implementation in Ruby

require "net/http"
require "json"
http = Net::HTTP.new("webtranslateit.com", 443)
request = Net::HTTP::Post.new("/api/projects/:api_token/strings/:string_id/locales/fr/translations", { "Content-Type" => "application/json" })
request.body = { "text" => "Cet user a déjà été invité", "status" => "status_proofread" }.to_json
http.request(request)

Example Implementation in PHP

<?php
  $api_key = "sekret";
  $string_id = "1234";
  $locale_code = "fr";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_URL, "https://webtranslateit.com/api/projects/" . $api_key . "/strings/". $string_id . "/locales/" . $locale_code . "/translations.json");
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, array("text" => "Cet user a déjà été invité", "status" => "status_proofread"));
  $response = curl_exec($ch);
  $p = json_decode($response, true);
  print_r($p);
  curl_close($ch);
?>