My company subscribed to Google Apps for Education. So, I though that access to Google Translate API would be included in our contract... but, that's not the case :(
Hummm... hummm... let's hack this for free.
Prerequisite is to have a Google account (even a free gmail account). What we will do is the create a sctipt on Google that will use the translate api freely and publish it as a REST web service which has the same JSON output format as the original.
Let's go!
var mock = {
parameter:{
q:'hello',
source:'en',
target:'fr'
}
};
function doGet(e) {
e = e || mock;
var sourceText = ''
if (e.parameter.q){
sourceText = e.parameter.q;
}
var sourceLang = 'auto';
if (e.parameter.source){
sourceLang = e.parameter.source;
}
var targetLang = 'en';
if (e.parameter.target){
targetLang = e.parameter.target;
}
var translatedText = LanguageApp.translate(sourceText, sourceLang, targetLang)
var json = {
'data': {
'translations' : [{
'translatedText' : translatedText
}]
}
};
return ContentService.createTextOutput(JSON.stringify(json)).setMimeType(ContentService.MimeType.JSON);
}
The original Translation API from Google is https://www.googleapis.com/language/translate/v2?q=[encodedText]&target=[language]&source=[language]&key=APIKEY
Your's will be something like https://script.google.com/macros/s/AKfyxxxxx/exec?q=[encodedText]&target=[language]&source=[language]
The output formats of the two REST service are identicals.
Enjoy!
Hummm... hummm... let's hack this for free.
Prerequisite is to have a Google account (even a free gmail account). What we will do is the create a sctipt on Google that will use the translate api freely and publish it as a REST web service which has the same JSON output format as the original.
Let's go!
- Connect to http://script.google.com and create an empty project.
- Copy paste the code below
- Publish it as web application
- Grant access to the url of your script to anonymous access if needed
var mock = {
parameter:{
q:'hello',
source:'en',
target:'fr'
}
};
function doGet(e) {
e = e || mock;
var sourceText = ''
if (e.parameter.q){
sourceText = e.parameter.q;
}
var sourceLang = 'auto';
if (e.parameter.source){
sourceLang = e.parameter.source;
}
var targetLang = 'en';
if (e.parameter.target){
targetLang = e.parameter.target;
}
var translatedText = LanguageApp.translate(sourceText, sourceLang, targetLang)
var json = {
'data': {
'translations' : [{
'translatedText' : translatedText
}]
}
};
return ContentService.createTextOutput(JSON.stringify(json)).setMimeType(ContentService.MimeType.JSON);
}
The original Translation API from Google is https://www.googleapis.com/language/translate/v2?q=[encodedText]&target=[language]&source=[language]&key=APIKEY
Your's will be something like https://script.google.com/macros/s/AKfyxxxxx/exec?q=[encodedText]&target=[language]&source=[language]
Enjoy!