Add Translation To Your App
Build your own machine and human translation powered applications with
SDL Language Cloud
Documentation Get an API key
var xhr = new XMLHttpRequest();
var text = 'Hello how are you?';
var string = '{"text":"' + encodeURI(text) + '", "from":"eng", "to":"fra"}';

xhr.onreadystatechange = function() {
  if (this.readyState == 4 && (this.status === 200 || this.status === 0)) {

  // this will output your translation response
  console.log(this.responseText);
  }
}

xhr.open("POST", "https://lc-api.sdl.com/translate", true);
xhr.setRequestHeader("Content-Type", "application/json");
// insert your api key here
xhr.setRequestHeader("Authorization", "LC apiKey=api_key_here");
xhr.send(string);
        
// example using jQuery.ajax

$.ajax({
  type: 'POST',
  url: "https://lc-api.sdl.com/translate",
  data: JSON.stringify({
    to: 'fra',
    from: 'eng',
    text: 'hello how are you?'
  }),
  headers: {
    // add your api key here
    Authorization: 'LC apiKey=api_key_here'
  },
  dataType: 'json',
  contentType: 'application/json'
}).done(function(response) {
  console.log(response.translation); // "Bonjour comment allez-vous?"
});
        
var request = require('request');

request({
  method: 'POST',
  url: https://lc-api.sdl.com/translate,
  headers: {
    Content-type: 'application/json',
    Accept: 'application/json',
    // add your api key here
    Authorization: 'LC apiKey=api_key_here'
  },
  body: JSON.stringify({
    to: 'fra',
    from: 'eng',
    text: 'hello how are you?'
  }),
  json:true
}, function(err, response, body) {
  console.log(body.translation); // "Bonjour comment allez-vous?"
});
        
using System;
using System.IO;
using System.Net;
using System.Text;

public enum HttpVerb
{
    GET,
    POST,
    PUT,
    DELETE
}

public class APIClient {
  public string Token { get; set; }
  private readonly string ContentType = "application/json";

  public APIClient(string token) {
    Token = token;       //your BeGlobal API key instead of `SDL Language Cloud API Key`
  }

  public string MakeRequest(string endpoint, HttpVerb method, string data) {
    var request = (HttpWebRequest)WebRequest.Create(endpoint);

    request.Method = method.ToString();
    request.ContentLength = 0;
    request.ContentType = ContentType;
    request.Headers.Add("Authorization", "LC apiKey=" + Token);

    if (!string.IsNullOrEmpty(data) && method == HttpVerb.POST) {
      var encoding = new UTF8Encoding();
      var bytes = Encoding.GetEncoding("iso-8859-1").GetBytes(data);
      request.ContentLength = bytes.Length;

      using (var writeStream = request.GetRequestStream()) {
        writeStream.Write(bytes, 0, bytes.Length);
      }
    }

    using (var response = (HttpWebResponse)request.GetResponse()) {
      var responseValue = string.Empty;

      if (response.StatusCode != HttpStatusCode.OK) {
        var message = String.Format("Request failed. Received HTTP {0}", response.StatusCode);
        throw new ApplicationException(message);
      }

      // grab the response
      using (var responseStream = response.GetResponseStream()) {
        if (responseStream != null) {
          using (var reader = new StreamReader(responseStream)) {
            responseValue = reader.ReadToEnd();
          }
        }
      }

      return responseValue;
    }
  }
}
        

These apps were built using our API