【问题标题】:Translating using Google Translate API使用 Google Translate API 进行翻译
【发布时间】:2014-04-21 09:39:12
【问题描述】:

我想使用以下代码作为将用户输入翻译成英语的程序的基础。我收到错误“找不到符号 - 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);
    }
}

【问题讨论】:

    标签: java google-translate machine-translation


    【解决方案1】:

    究竟什么是 GoogleApi? 你还没有声明,为了使用它..我没有完全理解这个程序,我建议你搜索网站或通过谷歌搜索一个程序来完成这个任务,有很多。

    【讨论】:

      【解决方案2】:

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

      注意事项:

      1. 如果你在代理后面,你需要让 jvm 意识到这一点。一种方法是通过静态初始化器,如下所示:

        静态的 { System.setProperty("http.proxyHost", HTTP_PROXY_HOST); System.setProperty("http.proxyPort", HTTP_PROXY_PORT); System.setProperty("https.proxyHost", HTTPS_PROXY_HOST); System.setProperty("https.proxyPort", HTTPS_PROXY_PORT); }

      2. 在运行配置中,通过如下设置环境变量来使您的 GOOGLE_API_KEY 可用:

      用于设置 API 密钥Check section titled "Setting up an API Key"

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-02-26
        • 2015-07-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-12-28
        相关资源
        最近更新 更多