Pages

Jan 28, 2011

Google translation from a server side.

I want to use the Google translation from a server side.
My Ideas are 1. run javascript on a server or 2. Direct http call to Google from server with PHP.

RESULT:

I selected "#2 Direct http call".

DETAIL:


1. run javascript on a server

I found "V8 JavaScript Engine".

"V8 JavaScript Engine" is a very good Engine,
but for me, it will take much time to make goolge objects in the V8.

How to install memo.

DOWNLOAD scons-2.0.1.tar.gz
# tar xzf scons-2.0.1.tar.gz
# cd scons-2.0.1
# python setup.py install --prefix=$HOME

# svn co http://google..... V8
# tar xzf scons-2.0.1.tar.gz
# cd v8
# scon
# cd samples
# g++ -I../include shell.cc -o shellv8 ../libv8.a -lpthread -m32

Test run javascript.

#./shellv8  test.js

test.js is:

print ('Hello' + ', World');
var x = 100;
var y = 200;
print ("x * y = " + (x * y));


Some objects, window and google, not implemented in shell.
It will take much time to make these objects.

2. Direct http call to Google from server PHP.

I re-read "Google Translate API Version 2".
it's is in Labs, but it has REST API.
REST is "Representational State Transfer".

like.
https://www.googleapis.com/language/translate/v2?key=AIzaSdkdN4TfYc0&q=flowers&source=en&target=fr&callback=handleResponse&prettyprint=true

No comments:

Post a Comment