Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用googletranslateapi进行翻译_Java_Google Translate_Machine Translation - Fatal编程技术网

Java 使用googletranslateapi进行翻译

Java 使用googletranslateapi进行翻译,java,google-translate,machine-translation,Java,Google Translate,Machine Translation,我想使用以下代码作为将用户输入翻译成英语的程序的基础。我收到错误“找不到符号-GoogleApi”。有人能帮我弄清楚该怎么办吗 import com.google.api.translate.Language; import com.google.api.translate.Translate; public class Main { public static void main(String[] args) throws Exception { // Set the

我想使用以下代码作为将用户输入翻译成英语的程序的基础。我收到错误“找不到符号-GoogleApi”。有人能帮我弄清楚该怎么办吗

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

public class Main {
    public static void main(String[] args) throws Exception {
        // Set the HTTP referrer to your website address.
        GoogleAPI.setHttpReferrer(/* Enter the URL of your site here */);

        // Set the Google Translate API key
        // See: http://code.google.com/apis/language/translate/v2/getting_started.html
        GoogleAPI.setKey(/* Enter your API key here */);

        String translatedText = Translate.DEFAULT.execute("Bonjour le monde", Language.FRENCH, Language.ENGLISH);

        System.out.println(translatedText);
    }
}
到底什么是GoogleApi?
为了使用它,您还没有声明。。我没有完全理解这个程序,我建议你搜索网站或通过谷歌搜索一个程序来完成这个任务,有很多

可以找到工作代码。它还有到github上完整代码库的链接

要记住的事情:

  • 如果您支持代理,则需要让jvm意识到这一点。一种方法是使用静态初始值设定项,如下所示:

    静止的 { System.setProperty(“http.proxyHost”,http\u PROXY\u HOST); System.setProperty(“http.proxyPort”,http\u PROXY\u PORT); System.setProperty(“https.proxyHost”,https\u PROXY\u HOST); System.setProperty(“https.proxyPort”,https\u PROXY\u PORT); }

  • 在运行配置中,通过将GOOGLE_API_密钥设置为环境变量,使其可用,如下所示:

  • 用于设置API密钥