Locale API

The Locale API is composed of 2 endpoints:

  • Add Locale — add a new locale or language to a project
  • Delete Locale — delete a locale or language from a project

Add Locale

This endpoint is only accessible by the read-write Project API key and is used to add a locale to a project.

/api/projects/:project_token/locales [POST]

Parameters:

  • id: the locale code (en-US, en_GB or fr for instance).
  • suffix_code: Optional, the suffix code (pirate or dev for instance). This will let you create a custome locale (en-pirate or en-dev for intance).
  • suffix_description: Optional, the description of the suffix (pirate or developers for instance).

If everything goes well, the server should respond with 202 Accepted in the response headers. Please note that the request could be acted upon since the rest of the process (creating language files for that locale) is processed in the background on WebTranslateIt’s server. Besides, these new files might not immediately be available.

Implementation Example in Ruby:

require "net/http"
http = Net::HTTP.new("webtranslateit.com", 443)
http.use_ssl = true
request = Net::HTTP::Post("/api/projects/:api_token/locales")
request.set_form_data({ "id" => locale_code }, ";")
response = http.request(request)

Implementation Example in PHP:

<?php
  $api_key = "sekret";
  $locale_code = "fr";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "https://webtranslateit.com/api/projects/" . $api_key . "/locales");
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, array("id" => $locale_code)); 
  $response = curl_exec($ch);
  print_r($response);
  curl_close($ch);
?>

Delete Locale

This endpoint is only accessible by the read-write Project API key and is used to delete a locale from a project.

/api/projects/:project_token/locales/:locale_code [DELETE]

If everything goes well, the server should respond with 202 Accepted in the response headers. Please note that the request could be acted upon since the rest of the process (deleting locale, linguistic files and translations for that locale) is processed in the background on WebTranslateIt’s server.

Implementation Example in Ruby:

require "net/http"
http = Net::HTTP.new("webtranslateit.com", 443)
http.use_ssl = true
request = Net::HTTP::Delete("/api/projects/:api_token/locales/:locale_code")
response = http.request(request)

Implementation Example in PHP:

<?php
  $api_key = "sekret";
  $locale_code = "fr";
  $ch = curl_init();
  curl_setopt($ch, CURLOPT_URL, "https://webtranslateit.com/api/projects/" . $api_key . "/locales/" . $locale_code);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
  $response = curl_exec($ch);
  print_r($response);
  curl_close($ch);
?>