Skip to content

Instantly share code, notes, and snippets.

@lsgrep
Last active August 29, 2015 14:11
Show Gist options
  • Save lsgrep/f1498efb5a9ea0a371af to your computer and use it in GitHub Desktop.
Save lsgrep/f1498efb5a9ea0a371af to your computer and use it in GitHub Desktop.
lichess 中文翻译成维语
;;(:require [org.httpkit.client :as httpkit])
;;(:require [clojure.java.io :as io])
;;(:require [net.cgrand.enlive-html :as html])
(defn get-raw-translation-result [src-text ]
(apply (comp first :content ) (html/select (html/html-snippet
(:body (http/post "http://tilmach.net"
{:form-params {:Source src-text}}))) [:textarea#Target])))
(defn translate [src]
(.trim (get-raw-translation-result src)))
;; testing translate function
(translate "你好")
(def ^:dynamic lichess-zh-url "https://raw.githubusercontent.com/ornicar/lila/master/conf/messages.zh")
(def temp-file (java.io.File/createTempFile "lichess-ug" ".txt"))
(.getAbsolutePath temp-file)
(with-open [rdr (io/reader lichess-zh-url)
wr (io/writer temp-file)
]
(binding [*out* wr]
(doseq [line (line-seq rdr)]
(println line )
(println (translate (second (.split line "="))))
)))
(slurp temp-file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment