Curl Global Community
Google Translation APIを使って翻訳 - Printable Version

+- Curl Global Community (https://communities.curl.com)
+-- Forum: Widgets/Gadgets/Curlets (https://communities.curl.com/forumdisplay.php?fid=15)
+--- Forum: Code Samples (https://communities.curl.com/forumdisplay.php?fid=16)
+--- Thread: Google Translation APIを使って翻訳 (/showthread.php?tid=104)



Google Translation APIを使って翻訳 - hokada - 07-07-2011

Google Translation API を使って翻訳をする方法です。

このGoogle Translation APIを利用するには、Google APIs ConsoleからAPI Keyを生成する必要があります。

Code:
{define-proc public {translate
                        version:int = 2,
                        key:String,
                        source:String,
                        source-locale:Locale,
                        target-locale:Locale
                    }:String
    def site =
        {format
            "https://www.googleapis.com/language/translate/v%i",
            version
        }
    def params =
        {format
            "key=%s&q=%s&source=%s&target=%s",
            key,
            {url-encode-string source},
            source-locale.name,
            target-locale.name
        }
    def target-url = {format "%s?%s", site, params}
    {with-open-streams
        tis = {read-open {url target-url}}
     do
        def json-val = {JsonValue-parse tis}
        {return
            || TODO: HTML decode
            {url-decode-string
                json-val["data"]["translations"][0]["translatedText"]
            }
        }
    }
}



RE: Google Translation APIを使って翻訳 - RobertShiplett - 08-02-2011

(07-07-2011, 10:54 AM)hokada Wrote: 私はhttp://developers.curl.com/people/rshiplett/blog/2011/08/01/global-communityでのウェブサイトに仁岡田氏の翻訳例の新しいバージョンを追加しました