Thread Rating:
  • 655 Vote(s) - 2.75 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Google Translation APIを使って翻訳
07-07-2011, 10:54 AM,
#1
Google Translation APIを使って翻訳
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"]
            }
        }
    }
}


Attached Files
.zip   Google Translation API_2.zip (Size: 1.5 KB / Downloads: 1,127)


Messages In This Thread
Google Translation APIを使って翻訳 - by hokada - 07-07-2011, 10:54 AM

Possibly Related Threads...
Thread Author Replies Views Last Post
  Google サジェストから候補データを取得し、オートコンプリートを作る hokada 0 7,071 07-07-2011, 10:49 AM
Last Post: hokada
Forum Jump:


Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('104')