Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 9 of 9

Thread: Google translate API

  1. #1
    Junior Member
    Join Date
    Dec 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Google translate API

    Hi all,

    really need an example how to translate a text with this API.

    I have implemented already the following:
    String googleUrl="https://www.googleapis.com/language/translate/v2?key=<My Key>";
    googleUrl+="&q=";
    googleUrl+=urlEncode(txtFeedback.getString());
    googleUrl+="&source=";
    googleUrl+=System.getProperty("microedition.locale ").substring(0, 2);
    googleUrl+="&target=en";
    HttpConnection googlAPI = null;
    DataInputStream dis = null;

    StringBuffer response = new StringBuffer();
    googlAPI = (HttpConnection)Connector.open(googleUrl);


    googlAPI.setRequestMethod(HttpConnection.GET);
    dis = new DataInputStream(googlAPI.openInputStream());
    int ch;
    while ((ch = dis.read()) != -1) {
    response.append((char) ch);
    }


    String tt = response.toString();
    tt = tt.substring(tt.indexOf("{"));
    JSONObject js = new JSONObject(tt);
    params +=js.getJSONObject("data").getJSONArray("translati ons").getJSONObject(0).getString("translatedText" ) + crlf;

    but this code throws the Certificate exception: certificate was issued by an unrecognized entity

    it throws the exception on my real device Samsung GT-S5230 as well as Emulator

    Really need help.

    Thank you all.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Google translate API

    javascript != java, and this appears to be a javascript question. You might try your luck on a dedicated javascript forum.

  3. #3
    Junior Member
    Join Date
    Dec 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Google translate API

    this is not javascript - I'm writing a j2me midlet

  4. #4
    Junior Member
    Join Date
    Dec 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Google translate API

    If I do something wrong it would be great to get an example how to call the google translate API from j2me midlet. Thank you.

  5. #5
    Junior Member
    Join Date
    Dec 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Google translate API

    Quote Originally Posted by copeg View Post
    javascript != java, and this appears to be a javascript question. You might try your luck on a dedicated javascript forum.
    this is not javascript - I'm writing a j2me midlet

    please, return back this thread to the Java ME (Mobile Edition) forum.

    thank you.

  6. #6
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Google translate API

    Quote Originally Posted by vozmen View Post
    this is not javascript - I'm writing a j2me midlet

    please, return back this thread to the Java ME (Mobile Edition) forum.

    thank you.
    Apologies. Thread moved

  7. #7
    Junior Member
    Join Date
    Dec 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Google translate API

    Seems working on Nokia but does not on the Samsung

  8. #8
    Think of me.... Mr.777's Avatar
    Join Date
    Mar 2011
    Location
    Pakistan
    Posts
    1,136
    My Mood
    Grumpy
    Thanks
    20
    Thanked 82 Times in 78 Posts
    Blog Entries
    1

    Default Re: Google translate API

    Quote Originally Posted by vozmen View Post
    Seems working on Nokia but does not on the Samsung
    I guess Samsung doesn't even support it. I have no experience of Google translate API but Google Mail API and i am quiet sure that mail api didn't work on Samsung while i was developing J2ME. (Almost 3 years back)

  9. #9
    Junior Member
    Join Date
    Dec 2011
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Google translate API

    Quote Originally Posted by Mr.777 View Post
    I guess Samsung doesn't even support it. I have no experience of Google translate API but Google Mail API and i am quiet sure that mail api didn't work on Samsung while i was developing J2ME. (Almost 3 years back)
    Thank you, I also have posted this question to the Samsung Mobile Forum, but still have no answer yet.

Similar Threads

  1. Translate Turbo Pascal code in Java
    By Mercenaire in forum What's Wrong With My Code?
    Replies: 1
    Last Post: December 4th, 2011, 04:52 AM
  2. Google Webservice Problem
    By buckeyeone in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 14th, 2010, 08:37 PM
  3. google search
    By nasi in forum Java Theory & Questions
    Replies: 7
    Last Post: April 2nd, 2010, 03:13 AM
  4. Help to translate from C to java
    By ighor10 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 27th, 2010, 07:36 AM
  5. Translate Java Code Into English
    By drkossa in forum Java Theory & Questions
    Replies: 4
    Last Post: November 27th, 2009, 02:52 PM

Tags for this Thread