Thursday, May 17, 2012

how to translate text from one language to other language through google translation in Android?


What is Google Translation Service?
Google Translate is a free automatic translator. It works without the intervention of human translators, using state-of-the-art technology instead. Google Translate currently supports translation between 57 languages.
How-To use Google Translate API in Android?
Using simple library google-api-translate-java[[http://code.google.com/p/google-api-translate-java/]], we can implement google translation with few lines of code.
Steps For integrating google translate api in android app.:
1:)First download jar file from [[http://code.google.com/p/google-api-translate-java/downloads/detail?name=google-api-translate-java-0.95.jar&can=2&q=]] and add it to project's build path.
2:)After importing library,you can easily translate text by simple code described below:
 Translate.setHttpReferrer("www.example.com");//here you can use any valid url.It's just for google to know who is consuming their service

        String translatedText=null;
        try {
             translatedText = Translate.execute("How are you", Language.ENGLISH, Language.FRENCH);//here You have to pass text to translate,language of you test and language to translate respectively.
        } catch (Exception e) {
            e.printStackTrace();
        }

7 comments:

  1. i have downloaded the api.. how to use it with my eclipse.?

    ReplyDelete
    Replies
    1. Use in your Activity class as per given Code

      Delete
  2. I want the example project, please....

    ReplyDelete
  3. check http://code.google.com/p/google-api-translate-java/

    ReplyDelete
  4. I am getting "Error retrieving translation" error.....What i have to do futher?

    ReplyDelete
  5. Code doesn't work. please give full project

    ReplyDelete