Translation Web Service - Translation engine REST API


1. Sign up for a frengly account, it's free.


2. Call our REST service

[POST] http://frengly.com/frengly/data/translateREST
   {
	src: 'en',
	dest: 'fr',
	text: 'this is a sample text in english',
	email: 'xxx@xxx.com',
	password: 'xxx',
	premiumkey: 'yyy'
   }					

src - source language code* to translate from
dest - destination language code* to translate to
text - a piece of text you want to translate
email - frengly account email, entered during registration (for older accounts please use username)
password - frengly account password
premiumkey - gives you almost unlimited access to the API (acquired from the buy page), not mandatory

* language codes: ar, bg, zhCN, zhTW, hr, cs, da, nl, en, et, tl, fi, fr, de, el, iw, hi, hu, is, id, ga, it, ja, ko, la, lv, lt, mk, mt, no, fa, pl, pt, ro, ru, sr, sk, si, es, sv, th, tr, vi


3. Sample Java client

package com.frengly.tests;

import java.io.InputStream;
import org.apache.commons.io.IOUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHeader;
import org.apache.http.protocol.HTTP;
import org.json.simple.JSONObject;

public class RestClient {
	
	@SuppressWarnings("unchecked")
	public static void main(String[] args) throws Exception {

		JSONObject object = new JSONObject();
		object.put("src", "fr");
		object.put("dest", "en");
		object.put("text", "Bonjour Monsieur");
		object.put("email", "xxx@xxx.com");
		object.put("password", "xxx");
		object.put("premiumkey", null);
			 
		HttpClient httpClient = HttpClientBuilder.create().build();
		RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(10000).build();
		HttpPost httpPost = new HttpPost("http://frengly.com/frengly/data/translateREST");
		httpPost.setConfig(requestConfig);
		
		StringEntity entity = new StringEntity(object.toJSONString(), "UTF-8");
		BasicHeader basicHeader = new BasicHeader(HTTP.CONTENT_TYPE,"application/json");		
		entity.setContentType(basicHeader);
		httpPost.setEntity(entity);
		
		HttpResponse response = httpClient.execute(httpPost);
		InputStream is = response.getEntity().getContent();
		String strResponse = IOUtils.toString(is, "UTF-8"); 
		
		System.out.println(strResponse);

	}	
}

4. Sample AngularJS client

$http.post('http://frengly.com/frengly/data/translateREST',
{	
   email: 'xxx@xxx.com', 
   password: 'xxx',
   text: 'Bonjour Monsieur',
   src: 'fr',
   dest: 'en'
}
).success(function(data, status, headers, config) {
   console.log(data);
});