GithubHelp home page GithubHelp logo

google-api-translate-java's People

google-api-translate-java's Issues

Translations via intermediate language sometimes return the intermediate language itself

What steps will reproduce the problem?
1. Choose from and to languages that do not form a valid language pair,
like Dutch to French, so that Translate will use English as the
intermediate language.
2. Pick a word that can be translated from Dutch to English, but not from
English to French.
3. Watch the result be the English translation.

What is the expected output? What do you see instead?
The expected output in this case is to return the dutch word itself, which
seems to be the normal response to an unknown word. In stead you get the
English translation.

What version of the product are you using? On what operating system?
0.28

Please provide any additional information below.
I'm using the api to translate single words from Dutch to the users native
lannguage.

Thanks so much for this API, I love the simplicity of it.

Original issue reported on code.google.com by [email protected] on 1 Apr 2008 at 9:35

Bad Request errors when translating between English and Japanese

What steps will reproduce the problem?
1. Take the demo code on the site and replace Bonjour le monde with 'Japan'
2. change the original language to ENGLISH and the Target language to Japanese
3. compile and run

What is the expected output? What do you see instead?
I'd expext to see 'nihon' in kanji, but I get this:
Server returned HTTP response code: 400 for URL:
http://translate.google.com/translate_t?langpair=en|jp&text=Japan

What version of the product are you using? On what operating system?
google-api-translate-java-0.22.jar on Windows XP (Japanese)

Please provide any additional information below.
I get this for even the simplest of words. The same tests with Engish,
Spanish, and French seem to work. I also tested with several basic words
and phrases in both directions with the same results.

Original issue reported on code.google.com by [email protected] on 5 Nov 2007 at 2:41

Patch for CROATION and FINNISH

CROATIAN has abbreviation 'hr', not 'cr'. 
FINNISH is missing in 'validLanguages' variable



Original issue reported on code.google.com by maticpetek on 29 Nov 2008 at 10:13

Attachments:

Not usable for automatic translations

What steps will reproduce the problem?
1. Run the sample program in a loop to simulate bulk translations.
2.
3.

What is the expected output? What do you see instead?
Expected: An infinite number of translations
Actual Result: 
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
        at java.lang.String.substring(Unknown Source)
        at java.lang.String.substring(Unknown Source)
        at com.google.api.translate.Translate.translate(Translate.java:44)
        at Test.main(Test.java:7)

What version of the product are you using? On what operating system?
google-api-translate-java-0.23.jar on Windows XP and Linux (OS doesn't matter)

Please provide any additional information below.
The problem is that after a large number of requests, Google's web site
freaks out and you get a "403 Forbidden" page which says:

"We're sorry...

... but your query looks similar to automated requests from a computer
virus or spyware application. To protect our users, we can't process your
request right now.

We'll restore your access as quickly as possible, so try again soon. In the
meantime, if you suspect that your computer or network has been infected,
you might want to run a virus checker or spyware remover to make sure that
your systems are free of viruses and other spurious software.

We apologize for the inconvenience, and hope we'll see you again on Google."

I can enter the captcha code and resume, but since it seems to set a cookie
in my browser, my automated translator is broken until Google's web servers
"trust" my IP address again.


Original issue reported on code.google.com by [email protected] on 20 Nov 2007 at 8:59

Attachments:

Par of my code that i don't know where to place

this is the code use to tranlate from one language to another when the
combination is not soported.
for example, if I need to translate "from Spanish to Japanese"
this code will first try to do it directly, and when it gets an
exception,will first try to use na intermediate 
language (usually english which is the
most supported) and after trying with the intermediate language will try
with Japanese.

Original issue reported on code.google.com by jbc.develop on 30 Nov 2007 at 10:36

Attachments:

Add method in Language Class to return the list of valid language pairs.

What steps will reproduce the problem?
1. None needed

What is the expected output? What do you see instead?
Expose the validLanguagePairs method in the Language class as a public
method 'List<String> getValidLanguagePairs()' so the list can be used to
populate drop down list boxes in an UI application.

What version of the product are you using? On what operating system?
0.26

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 18 Dec 2007 at 3:27

Improvement proposal -- try to use servise for AJAX

Hello Rich!

This is not bug report. It is improvement proposal. Your project looks 
good...

You use standard web form address to get translation. You build request, 
send it and after all you have to mine translation(s) from the web site 
source code. 

Why not to use servise, which is prepared primarily for AJAX API but is 
applicable also for other languages. See 
http://code.google.com/apis/ajaxlanguage/documentation/#fonje 
for details.

It could solve the problem with blocking for to much requests. Maybe.

Original issue reported on code.google.com by jaroslavbauml on 9 May 2008 at 12:11

Suggestion for translating html source

Great stuff - many thanks!

Would it be possible to support html source in addtion to text? I saw
google's ajax translation api is supporting html source translation and
seems to me a java verion would be really great!

Best regards,

Qunhuan Mei

Original issue reported on code.google.com by [email protected] on 10 May 2009 at 10:21

API traslate to .Net

Hi, I´m a developer of web and desktop applications, my speciality is Java 
and .Net and I want traslate your java code to .Net Code and thus 
contribute with this great iniciative.

Im from Spain and not speak very well english, what do you think about my 
suggest?

My email is [email protected]

Best regards.
Emmerson Miranda.


Original issue reported on code.google.com by emmerson.miranda on 26 Feb 2008 at 8:35

Not able to Translate to English to Arabic Using googles Unofficial API

What steps will reproduce the problem?
1. Not able to Translate to English to Arabic Using googles Unofficial API
2.
3.

What is the expected output? What do you see instead?


What version of the product are you using? On what operating system?


Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 19 Nov 2007 at 5:42

English to Croation translation is not working

... it throws exceptions:

java.lang.Exception: [google-api-translate-java] Error retrieving 
translation.
    at com.google.api.translate.Translate.retrieveTranslation
(Translate.java:85)
    at com.google.api.translate.Translate.translate(Translate.java:57)
    at gluposti.GoogleTranslateTest$1.actionPerformed
(GoogleTranslateTest.java:60)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown 
Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown 
Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased
(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown 
Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown 
Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown 
Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.lang.ClassCastException: org.json.JSONObject$Null cannot 
be cast to org.json.JSONObject
    at com.google.api.translate.Translate.retrieveTranslation
(Translate.java:79)
    ... 27 more

Original issue reported on code.google.com by [email protected] on 24 Nov 2008 at 1:59

post > 1024 byte is good

/**
 * Translate.java
 *
 * Copyright (C) 2007,  Richard Midwinter
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, 
USA.
 */
package com.google.api.translate;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

/**
 * Makes the Google Translate API available to Java applications.
 * 
 * @author Richard Midwinter
 * @author Emeric Vernat
 * @author Juan B Cabral,chinese xiatianQQ11602011
 */
public class Translate {

    private static final String ENCODING = "UTF-8";
    private static final String INTERMEDIATE_LANGUAGE = Language.ENGLISH;
    private static final String URL_STRING 
= "http://translate.google.com/translate_t?langpair=";
    private static final String TEXT_VAR = "&text=";
    private static final int RATE_DELAY = 10; // 以前的值:2000,我得更小了

    private static boolean rateControl = true;
    private static long lastQueryTime = 0l;

    /**
     * Are we throttling queries to prevent being blocked? Defaults to 
true.
     * 
     * @return Returns true if throttling query frequency.
     */
    public static boolean isUsingRateControl() {
        return rateControl;
    }

    /**
     * Allows turning off rate control
     * 
     * @param rateControl Turns on rate control if true, off if false.
     */
    public static void setUsingRateControl(boolean rateControl) {
        Translate.rateControl = rateControl;
    }

    /**
     * Reads an InputStream and returns its contents as a String. Also 
effects rate control.
     * @param inputStream The InputStream to read from.
     * @return The contents of the InputStream as a String.
     * @throws Exception
     */
    private static String toString(InputStream inputStream) throws 
Exception {
        StringBuilder outputBuilder = new StringBuilder();
        try {
            while (rateControl && (lastQueryTime+RATE_DELAY > 
System.currentTimeMillis())) {
                try {
                    Thread.sleep(lastQueryTime+RATE_DELAY-
System.currentTimeMillis());
                } catch (InterruptedException e) {
                }
            }
            String string;
            if (inputStream != null) {
                BufferedReader reader = new BufferedReader(new 
InputStreamReader(inputStream, ENCODING));
                while (null != (string = reader.readLine())) {
                    outputBuilder.append(string).append('\n');
                }
            }
            if (rateControl) lastQueryTime = System.currentTimeMillis
();
        } catch (Exception ex) {
            throw new Exception("[google-api-translate-java] Error 
reading translation stream.", ex);
        }
        return outputBuilder.toString();
    }

    /**
     * Translates text from a given language to another given language 
using Google Translate
     * http://www.google.com/translate_t?hl=zh-CN
     * @param text The String to translate.
     * @param from The language code to translate from.
     * @param to The language code to translate to.
     * @return The translated String.
     * @throws MalformedURLException
     * @throws IOException
     */
    public static String translate(String text, String from, String to) 
throws Exception {
        if(Language.CHINESE.equals(from) && 
Language.CHINESE_TRADITIONAL.equals(to))
            from = Language.CHINESE_SIMPLIFIED;
        if (Language.isValidLanguagePair(from, to)) {
            return retrieveTranslation(text, from, to);
        } else {
            return retrieveTranslation(retrieveTranslation(text, from, 
INTERMEDIATE_LANGUAGE), INTERMEDIATE_LANGUAGE, to);
        }
    }

    /***
     * 设置代理
     * @param szProxyServer
     * @param szPort
     */
    public static void setProxy(String szProxyServer, String szPort)
    {
        System.getProperties().put("proxySet", "true");
        System.getProperties().put("proxyHost", szProxyServer);
        System.getProperties().put("proxyPort", szPort);
    }

    /**
     * Forms an HTTP request and parses the response for a translation.
     * 
     * @param text The String to translate.
     * @param from The language code to translate from.
     * @param to The language code to translate to.
     * @return The translated String.
     * @throws Exception
     */
    private static String retrieveTranslation(String text, String from, 
String to){//  throws Exception 
        try {
            if(null == text || 0 == text.length())return "";

            StringBuilder url = new StringBuilder();
            url.append(URL_STRING).append(from).append('|').append(to);

            HttpURLConnection uc = (HttpURLConnection) new URL
(url.toString()).openConnection();
            try {

                uc.setRequestProperty("User-Agent", "Mozilla/4.0 
(compatible; MSIE 7.0; Windows NT 5.1)");
                // 用post的方式能翻译大于1024字节的内容
                uc.setDoOutput(true);
                OutputStream out = uc.getOutputStream();
                out.write(("langpair=" + from + "|" + to + 
TEXT_VAR + URLEncoder.encode(text, ENCODING)).getBytes());
                out.flush();
                out.close();
                String page = toString(uc.getInputStream());

                int resultBox = page.indexOf("<div id=result_box 
dir=");        
                if (resultBox < 0) throw new Error("No translation 
result returned.");

                String start = page.substring(resultBox);
                return start.substring(start.indexOf('>')+1, 
start.indexOf("</div>"));
            } finally { // 
http://java.sun.com/j2se/1.5.0/docs/guide/net/http-keepalive.html
                try{
                    uc.getInputStream().close();
                }catch(Exception e){e.printStackTrace();}
                if (null != uc.getErrorStream()) uc.getErrorStream
().close();
                uc = null;
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return "";
    }
}

Original issue reported on code.google.com by [email protected] on 29 Jan 2008 at 6:06

Google added more languages -

The newly featured languages include Bulgarian, Croatian, Czech, Danish,
Finnish, Hindi, Norwegian, Polish, Romanian and Swedish.

http://googleblog.blogspot.com/2008/05/google-translate-adds-10-new-languages.ht
ml

It would be great to add those in...


Original issue reported on code.google.com by gedas%[email protected] on 26 May 2008 at 8:36

package com.google.api.translate does not exist

Once I compiled the sample code after putting jar file under C:\Program
Files\Java\jdk1.6.0_03\lib I am getting error like "package
com.google.api.translate does not exist" 

What is the expected output? What do you see instead?
I am simply trying to convert a text from English to chinese


Original issue reported on code.google.com by [email protected] on 28 Jan 2008 at 8:04

chinese xiatianQQ11602011: no proxy and servlet, I am add it, fixed

/***
     * 设置代理
     * @param szProxyServer
     * @param szPort
     */
    public static void setProxy(String szProxyServer, String szPort)
    {
        System.getProperties().put("proxySet", "true");
        System.getProperties().put("proxyHost", szProxyServer);
        System.getProperties().put("proxyPort", szPort);
    }


package com.google.api.translate;

import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class TranslateServlet extends HttpServlet{

    // 代理信息
    private String szProxyServer = null;
    private String szPort = null;
    private String Charset = "UTF-8";

    private static final long serialVersionUID = 1L;
    public void service(HttpServletRequest request, 
HttpServletResponse response)
            throws ServletException, IOException {
        response.setContentType("text/plain;charset=" + Charset);
        OutputStream out = response.getOutputStream();
        try {
            String szOut = Translate.translate
(request.getParameter("data"), request.getParameter("from"), 
request.getParameter("to"));
            // System.out.println(szOut);
            out.write(szOut.getBytes(Charset));
            szOut = null;
        } catch (Exception e) {
        }
        out.flush();
        out.close();
    }
    public void destroy() {
        if(null == szProxyServer || 0 == szProxyServer.trim
().length())
            System.getProperties().put("proxySet", "false");
        Charset = szProxyServer = szPort = null;
        super.destroy();
    }

    /***
     * 初始化配置并设置代理
     */
    public void init(ServletConfig config) throws ServletException
    {
        szProxyServer = config.getInitParameter("ProxyServer");
        szPort = config.getInitParameter("Port");
        if(null != config.getInitParameter("Charset"))
          Charset = config.getInitParameter("Charset");
        if(null != szProxyServer && 0 < szProxyServer.trim().length
())
        {
            Translate.setProxy(szProxyServer, szPort);
        }
        super.init(config);
    }
}

Original issue reported on code.google.com by [email protected] on 29 Jan 2008 at 6:10

Attachments:

Right angle bracket precedes translated text in result

What steps will reproduce the problem?
1. Use translater
2.
3.

What is the expected output? What do you see instead?

Expect translated text, get translated text preceded by a right angle 
bracket.


What version of the product are you using? On what operating system?

0.26



Please provide any additional information below.

Instead of expecting the result to be an exact number of characters from 
the tag string, search for the first right angle bracket.


Original issue reported on code.google.com by [email protected] on 16 Jan 2008 at 6:41

Unsupported Class Verision Error

Lead up:
1. Importing api into project in Eclipse
2. Calling Translate.translate() with appropriate methods:

japanese = Translate.translate(english, Language.ENGLISH,
                    Language.JAPANESE); 

The following error is generated:
Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad
version number in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:675)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:316)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:280)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:374)
    at Translator.getEngrish(Translator.java:29)
    at Translator.main(Translator.java:21)



Original issue reported on code.google.com by [email protected] on 8 Nov 2008 at 6:13

IndexOutOfBoundsException when translating English to Arabic BETA

What steps will reproduce the problem?
1. Write the following code in a JSP:

if(request.getParameter("textToTranslate") != null 
    && request.getParameter("textToTranslate").trim()!="") {
        String textToTranslate = request.getParameter("textToTranslate");
        String translatedText = Translate.translate(textToTranslate,
Language.ENGLISH, Language.ARABIC);
        out.println(translatedText);
    }

The JSP must be passed some Arabic text from another page as form fields.

2. Run the page.

What is the expected output? What do you see instead?

The expected output is a page that has the Arabic Translation. It shows an
empty page with the following exception:
java.lang.StringIndexOutOfBoundsException: String index out of range: -1
    at java.lang.StringBuffer.substring(StringBuffer.java:861)
    at com.google.api.translate.Translate.translate(Translate.java:47)
    at org.apache.jsp.translate_jsp._jspService(translate_jsp.java:59)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:328)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:315)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilt
erChain.java:269)
    at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.
java:188)
    at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:2
10)
    at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:1
74)
    at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
    at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108
)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
    at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConne
ction(Http11BaseProtocol.java:665)
    at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:52
8)
    at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorker
Thread.java:81)
    at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:68
5)
    at java.lang.Thread.run(Thread.java:799)



What version of the product are you using? On what operating system?
I am using version 0.2 on Windows XP and running the web application on
Tomcat v5.5.


Original issue reported on code.google.com by [email protected] on 31 Oct 2007 at 1:23

Character encoding problems

What steps will reproduce the problem?
System.out.println(
  Translate.translate("size", Language.ENGLISH, Language.GERMAN)
); 

What is the expected output? What do you see instead?
Expected: Größe
Got: Größe

What version of the product are you using? On what operating system?
Windows XP, German. Important system properties (System.getProperties()):
java.vm.version=1.6.0_01-b06 
user.country=CH 
file.encoding=Cp1252 
user.language=de

Original issue reported on code.google.com by [email protected] on 27 Nov 2007 at 2:03

Bigger/buffer translation support.

Hi Rich,

First of all ,thanks a lot for your wonderful and useful api !

I attached some support for buffer translation 
( I think that it is up to 15K chars , and in my code I loop if it is 
bigger than that ... )

And again - thanks a lot !
Zac .


Original issue reported on code.google.com by [email protected] on 20 Feb 2008 at 9:48

Attachments:

Bad version number in .class file

Hi.

I get a "Bad version number" error. Probably you've compiled the classes
with Java 6, and I work with Java 5.

¿Do you have .class files with Java5 compliance level? ¿Or can you send me
the source code so I can compile it?

Thank you. 

Mi e-mail: [email protected]

Original issue reported on code.google.com by [email protected] on 7 Oct 2008 at 7:20

Getting Output as ? for Chinese conversion

What steps will reproduce the problem?
1. Developed a Java program using this API for Convertion. 
2. The program is working fine but gives error when converting English to 
Chinese. I am getting  a '?' when trying to convert 'hello' to Chinese
Attached is my Java file (Tranlator.java). 


What is the expected output? What do you see instead?


What version of the product are you using? On what operating system?
google-api-translate-java-0[1].4.jar on Windows XP. I have installed the 
East Asian Package of the Windows and i am able to view the correct 
translation of Chinese in browser.

Please provide any additional information below.

Original issue reported on code.google.com by [email protected] on 14 May 2008 at 11:52

Attachments:

Provide mapping from language abbreviations to full names

The API currently provides a list of valid languages, but this list is only
provided as a set of abbreviations. It might be nice if there was a way
convert these abbreviations to their full names, e.g. "en" -> "English,
"de" -> "German", etc. 

A facility like this would make it easier for clients of the library to
upgrade (i.e. as new languages are added) since they wouldn't need to keep
their own abbreviation-to-name mapping up-to-date.

Original issue reported on code.google.com by austin.bingham on 15 Dec 2008 at 11:19

你的代码太不完整了

粗粗看了你的代码一下,觉得如下问题不做解决可能会影响��
�用。
1、代理服务器(ex)
Properties prop = System.getProperties();
prop.put("http.proxyHost","202.105.182.19");
prop.put("http.proxyPort","80");
我是从2006年就用google翻译来更新数据库里的指定内容。发现�
��果使用google翻译
过于频繁GOOGLE就会误认为你是来功击。所以我的做法是加入��
�多的代理服务器来做
轮询:
String urlstr = engineUrl + "?text=" + encodeText(translateText)
                + "&langpair=" + langpair;
        URL url = new URL(urlstr);
        Properties prop = System.getProperties();
        if (Integer.valueOf(OrderProxy)%10==0){
            prop.put("http.proxyHost","202.105.182.19");
            prop.put("http.proxyPort","80");    
        }else if (Integer.valueOf(OrderProxy)%9==0){
            prop.put("http.proxyHost","202.105.182.15");
            prop.put("http.proxyPort","80");    
        }else if (Integer.valueOf(OrderProxy)%8==0){
            prop.put("http.proxyHost","216.89.101.4");
            prop.put("http.proxyPort","80");    
        }else if (Integer.valueOf(OrderProxy)%7==0){
            prop.put("http.proxyHost","218.7.48.22");
            prop.put("http.proxyPort","8080");  
        }else if (Integer.valueOf(OrderProxy)%6==0){
            prop.put("http.proxyHost","222.89.169.73");
            prop.put("http.proxyPort","3128");  
        }else if (Integer.valueOf(OrderProxy)%5==0){
            prop.put("http.proxyHost","61.181.156.98");
            prop.put("http.proxyPort","3128");  
        }else if (Integer.valueOf(OrderProxy)%4==0){
            prop.put("http.proxyHost","218.25.105.18");
            prop.put("http.proxyPort","3128");  
        }else if (Integer.valueOf(OrderProxy)%3==0){
            prop.put("http.proxyHost","202.105.182.11");
            prop.put("http.proxyPort","80");    
        }else if (Integer.valueOf(OrderProxy)%2==0){
            prop.put("http.proxyHost","202.105.182.13");
            prop.put("http.proxyPort","80");    
        }else{
            prop.put("http.proxyHost","202.105.182.16");
            prop.put("http.proxyPort","80");
        }       

        URLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestProperty("User-agent", "IE/6.0");      
        connection.connect();
2、你的错误处理呢?如果实际使用用户因多种原因发生错误�
��,他们如何追溯?
[email protected]

Original issue reported on code.google.com by [email protected] on 29 Oct 2007 at 1:49

No translation result returned.

What steps will reproduce the problem?
1. Call Translate.translate in a loop. 
2. I created an object of Translate and setUsingRateControl to false
3.

What is the expected output? What do you see instead?
Expected output is translated string but i get exception instead. Below is 
my Exception.
Exception in thread "main" java.lang.Error: No translation result returned.
        at com.google.api.translate.Translate.retrieveTranslation
(Translate.java:135)
        at com.google.api.translate.Translate.translate(Translate.java:107)
        at camel.HelloWorldTranslate.main(HelloWorldTranslate.java:26)
Java Result: 1



What version of the product are you using? On what operating system?
I'm using google-api-translate-java-0.30.jar

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 19 Apr 2008 at 5:08

Translator fails for repeated translations.

What steps will reproduce the problem?
1. Translated the properties file many times from English to French.
2.
3.

What is the expected output? What do you see instead?
It has to convert all the values to french.

Exception in thread "main" java.lang.Error: No translation result returned.
        at
com.google.api.translate.Translate.retrieveTranslation(Translate.java
:135)
        at com.google.api.translate.Translate.translate(Translate.java:107)
        at Translator.translate(Translator.java:74)
        at Translator.main(Translator.java:114)

What version of the product are you using? On what operating system?
google-api-translate-java-0.30.jar.

Please provide any additional information below.
I got above error when i am in between traslating something and from then
onwards i am not able to translate at all :(. please help me in this regard.



Original issue reported on code.google.com by [email protected] on 23 Apr 2008 at 4:48

Auto language detect



How to have auto language detect in JAVA ?

Original issue reported on code.google.com by vdharankar on 11 Feb 2009 at 5:44

again

you're welcome to use my idea of "intermediate lenguage"

i don't care if you change my GPL3 for GPL2

but please add my name to the source code

i work in new enhacement


Original issue reported on code.google.com by jbc.develop on 11 Dec 2007 at 3:59

Error in translation

I have used the google-api-translate-java for translation.
In eclipse i have created a java project added the jar file to my project
and tested the example u have given .

This is my code :

import com.google.api.translate.Language;
import com.google.api.translate.Translate;

public class TranslatorDemo 
{
     public static void main(String[] args) 
     {
            try 
            {
              String translatedText = Translate.translate("Salut le monde",
Language.FRENCH, Language.ENGLISH);
              System.out.println(translatedText);
            } 
            catch (Exception ex) 
            {
              ex.printStackTrace();
            }
     }
}


The Error i got is :


Exception in thread "main" java.lang.UnsupportedClassVersionError: Bad
version number in .class file
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
    at com.vsoftcorp.suvikas.TranslatorDemo.main(TranslatorDemo.java:13)

Please do help me




Original issue reported on code.google.com by [email protected] on 27 Feb 2009 at 12:49

Proxy server support

Hi,
I have a problem with our company proxy server that filtrate all HTTP
request. For that reason I change you Translate class to work with proxy.
I add only one overload to method translate(String text, String from,
String to,Proxy proxy) and change HTTP request method retrieveTranslation().

Could you add this proxy support to next API version?
Thanks,
       Plamen Ivanov

Original issue reported on code.google.com by [email protected] on 4 Mar 2009 at 4:17

Attachments:

Encoding-related issues

What steps will reproduce the problem?
1. Translate the word "ok" from English to French using the API

What is the expected output? What do you see instead?
I expect to get "d'accord" but I get "d&#39;accord".

What version of the product are you using? On what operating system?
This is with the head of the SVN tree

I ran this under a debugger to verify that it was a problem with the API 
and not my program. The string coming out of the translate call has the bad 
text in it.

It looked like older encoding related issues in your system were supposed 
to be fixed, so I created a new ticket...sorry if this is a repeat.

Original issue reported on code.google.com by austin.bingham on 13 Jan 2009 at 7:36

languages missing in "Language.validLanguages"

What steps will reproduce the problem?
1. System.out.println(Language.validLanguages);
2.
3.

What is the expected output? What do you see instead?
[ar, zh, zh-CN, zh-TW, en, fr, de, it, ja, ko, pt, ru, es]
When we see all languages we can use, it shows us 15 languages, but when we
run "Language.validLanguages" it only appears 13 languages (above).

What version of the product are you using? On what operating system?
0.30.
Windows XP

Please provide any additional information below.


Original issue reported on code.google.com by albertoivo on 24 Apr 2008 at 3:52

Support for other languages

What steps will reproduce the problem?
1.
2.
3.

What is the expected output? What do you see instead?


What version of the product are you using? On what operating system?


Please provide any additional information below.

 The ajax based translator is supporting more languages than what is
supported by java based translator. We have a typical situation to convert
our business dictionary to many other languages.
google-api-translate-java-0.4 library is very much helpful to us. So we
would like to see this distribution supporting many other languages
(atleast that are supported by ajax based tool). Thanks in advance.

Original issue reported on code.google.com by [email protected] on 3 Jul 2008 at 4:53

Improvement proposal -- try to use servise for AJAX

Hello Rich!

This is not bug report. It is improvement proposal. Your project looks 
good...

You use standard web form address to get translation. You build request, 
send it and after all you have to mine translation(s) from the web site 
source code. 

Why not to use servise, which is prepared primarily for AJAX API but is 
applicable also for other languages. See 
http://code.google.com/apis/ajaxlanguage/documentation/#fonje 
for details.

It could solve the problem with blocking for to much requests. Maybe.

Original issue reported on code.google.com by jaroslavbauml on 9 May 2008 at 12:11

[changes/question] Why You didn't use enum

I changed Language class to enum. I think this is better because in
Translate class I removed language validation (lines 71 to 73) because now
validation is on compiler scope. Javac check that user use correct
languages names. Now they has only limited languages list not a
unrestricted String.
I attach new version of Language and Translate files.

I interested in make more changes and re factorize code. 
pls contact with me via email.

Koziolek

Original issue reported on code.google.com by [email protected] on 9 Mar 2009 at 8:04

Attachments:

Support for telugu language.

HI,

The jar is simply excellent. Its perfectly working for HINDI. My
requirement is to have TELUGU option also and unfortunately it seems the
current jar google-api-translate-java-0.53.jar is not supporting it.

Can you please advice what i have to do for this?

Thank you very much in advance.

BR,
Surya
[email protected]

Original issue reported on code.google.com by [email protected] on 12 Jun 2009 at 11:32

close the streams

What version of the product are you using? On what operating system?
from subversion

Please provide any additional information below.
I suggest you close streams like below in order to avoid memory leaks.

    HttpURLConnection connection = (HttpURLConnection)new
URL(url.toString()).openConnection();
    InputStream in = connection.getInputStream();
    try {
      connection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible;
MSIE 7.0; Windows NT 5.1)");

      String page = toString(in);
      int resultBox = page.indexOf("<div id=result_box dir=");

      if (resultBox < 0) {
        throw new Error("No translation result returned.");
      }

      String start = page.substring(resultBox);
      return start.substring(27, start.indexOf("</div>"));
    } finally {
      // http://java.sun.com/j2se/1.5.0/docs/guide/net/http-keepalive.html
      in.close();

      InputStream error = connection.getErrorStream();
      if (error != null) {
        error.close();
      }
    }


Original issue reported on code.google.com by [email protected] on 1 Dec 2007 at 1:42

key error when using tranlate with google maps

At google maps api you find several times the message that when you use 
tranlate with google maps that after translation you don't get the map 
anymore because you have a wrong key!

Is this a known error here and is it ubder construction or is there a 
bypass or is there already a solution?

Any suggestions?

Nico Oudshoorn

Original issue reported on code.google.com by [email protected] on 23 Sep 2008 at 2:59

Question about Language

Hi,

I would like to know if there is a reason to have choosen the String 
values of languages not matching a "Locale.toString()" ??

I m thinking mainly about Language.CHINESE_SIMPLIFIED (zh-CN) and 
Locale.SIMPLIFIED_CHINESE (zh_CN)

An helper method on Language class could do the job ?

Original issue reported on code.google.com by [email protected] on 5 Jan 2009 at 2:58

Thai Language Support

Notices that some other new languages have been added to the Translate 
facility, most specifically Thai, many thanks Google.

New languages support was added to the API in September... can the 
languages added after this date also be added.. 

Original issue reported on code.google.com by [email protected] on 11 Feb 2009 at 4:03

java.lang.Error: No translation result returned on Google Quickstart test

What steps will reproduce the problem?
1. goto http://code.google.com/p/google-api-translate-java 
2. create a test class from Quickstart
3. Run test

What is the expected output? What do you see instead?

The expected result was a translation of "Salut le monde" from French to
English
Instead we received  java.lang.Error: No translation result returned.

What version of the product are you using? On what operating system?
We are using version 0.5 on XP platform


Please provide any additional information below.


Original issue reported on code.google.com by michael.rossovsky on 10 Nov 2008 at 12:59

Attachments:

when i add library to my j2me project have compiler error

What steps will reproduce the problem?
1. when i add library to my j2me project
2.
3.

What is the expected output? What do you see instead?
Error preverifying class com.json.JOSNOBJECT

What version of the product are you using? On what operating system?
netbean6.5 and windows server 2003

Please provide any additional information below.


Original issue reported on code.google.com by [email protected] on 14 Oct 2008 at 7:13

Turkish

Hello, can you add Turkish please

Original issue reported on code.google.com by sahinyanlik on 8 Feb 2009 at 10:43

The translation service always returns "no results"

What steps will reproduce the problem?
After few days of normal processing, the translation doesn't return 
results at every time in the server. In my developer environment the api 
works good.

What is the expected output? What do you see instead?
Te service ran succesfully but, apparently, after 2-3 days of operation, 
the translation always returns 0 results. It seems as if my IP address had 
been freaked or banned from Google due too many calls to the service.

What version of the product are you using? On what operating system?
google-api-translate-java-0.27 over Linux ubuntu with apache-tomcat 5.5.23

Is possible to get a more powerfull license, even with cost, that allow me 
to use the translation service according to my needs.

Thank you very much in advance


Original issue reported on code.google.com by [email protected] on 23 Jan 2008 at 8:04

Improving error handling

Currently many errors, eg. IOExceptions and MalformedURLExceptions are just
thrown from the translate method.

Many of these should throw simple errors that provide a facade - users
can't do anything if the format of Google Translate URLs change nor do they
need to know what line of our code the error occurred on.

A logging API is probably worth investigating as long as it doesn't add
dependencies.

Original issue reported on code.google.com by [email protected] on 2 Dec 2007 at 1:59

Wrong characters in translated text (bad character decoding)

I get garbage characters in the translated text because of bad character
decoding (I'm using a Mac, the default encoding on my system isn't UTF-8)

The solution to this is to explicitly configure the input stream reader to
use UTF-8 as character encoding:

new BufferedReader(new InputStreamReader(inputStream, "UTF-8"));


Rob

Original issue reported on code.google.com by [email protected] on 24 Nov 2007 at 8:43

Translate API T&C's requires a "Referer" in the header or an API Key

If you look at the API usage Terms and Conditions at a minimum Google
translate requires a "Referer" in the header or an API Key. There is
currently no way to pass in this information.

A method to set the "Referer" and/or "API Key" is required and this must be
passed to Google in the request.

Original issue reported on code.google.com by [email protected] on 2 Apr 2009 at 3:39

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.