Hi Sharavana,
there's nothing android specific about the API, it's a simple HTTP request. So once you get it working on your PC, it'll also work on android.
( please see
http://code.google.com/apis/language/translate/v2/getting_started.html )
here's some sample java code to get you started:
// requestSample = "GET
https://www.googleapis.com/language/translate/v2?key=INSERT-YOUR-KEY&source=en&target=fr&q=please";
private final String requestURL = "
https://www.googleapis.com/language/translate/v2?key=";
private final String requestKey = "INSERT-YOUR-KEY";
private final String requestSrc = "&source=";
private final String requestDst = "&target=";
private final String requestTxt = "&q=";
public String requestTranslation( String txt, String src, String dst ) {
String request = requestURL + requestKey + requestSrc + src + requestDst + dst + requestTxt;
try {
request += URLEncoder.encode( txt, "UTF-8" );
URL url = new URL( request );
URLConnection connection = url.openConnection();
connection.connect();
InputStreamReader inputStreamReader = new InputStreamReader( connection.getInputStream(), "UTF-8" );
BufferedReader in = new BufferedReader( inputStreamReader, 512 );
StringBuffer sb = new StringBuffer();
String line;
while ( ( line = in.readLine() ) != null ) {
sb.append( line );
}
in.close();
return sb.toString();
}
catch ( Exception e ) {
e.printStackTrace();
}
return null;
}
The code above will return the json below, which you will need to parse. A good json parser should also convert HTML encoding ( eg. ' ).
enjoy, Bruno
json returned = [{ "data": { "translations": [ { "translatedText": "s'il vous plaît" } ] }}]