markdown 用httpclient谷歌翻译

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown 用httpclient谷歌翻译相关的知识,希望对你有一定的参考价值。

(ns google_translate.10_google_translate_httpclient
  (:require [clojure.string :as string]
            [clj-http.client :as http]
            )
  (:use [alexcoding.util.json])
  )



(defn translate [s options]
  "Translate text using Google Translate API v2."
  (if (string/blank? s) ""
                        (let [params {"key" (:key options)
                                      "source" (:source options)
                                      "target" (:target options)
                                      "q" s}
                              resp (http/post "https://www.googleapis.com/language/translate/v2"
                                              {:as :json
                                               :debug false
                                               :headers {"X-HTTP-Method-Override" "GET"}
                                               :form-params params})]
                          (:translatedText (first (:translations (:data (:body resp)))))
                          )))

(defn -main [& words]
  (print (translate (first words) {:key (get-secret-key ["google-translate" "key"])
                                   :source "en"
                                   :target "zh-CN"})))





(comment
  (-main "what a nice day!"))

以上是关于markdown 用httpclient谷歌翻译的主要内容,如果未能解决你的问题,请参考以下文章

谷歌在线翻译怎么用?

谷歌在线翻译怎么用?

markdown HttpClient的

更新 TKK 失败,请检查网络连接。谷歌翻译 translation插件不能用解决办法 亲测有效

google谷歌翻译插件-网页一键翻译

谷歌浏览器怎么设置markdown插件