Created
May 10, 2011 13:26
-
-
Save youz/964463 to your computer and use it in GitHub Desktop.
ライトニング・リーズィョンルブルム間隙の氷結界の文章をノムリッシュローカライズします (リージョン内の文章をノムリッシュ翻訳します)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; -*- mode:lisp; package; nomurish -*- | |
(eval-when (:compile-toplevel :load-toplevel :execute) | |
(require "xml-http-request") | |
(require "dom")) ; https://gist.github.com/705102 | |
(defpackage "nomurish" | |
(:use "lisp" "editor")) | |
(in-package "nomurish") | |
(export '(nomurize)) | |
(defmacro whenlet (var test &body body) | |
`(let ((,var ,test)) (when ,var ,@body))) | |
(defun nomurize (text &optional (level 2)) | |
(whenlet res (xhr:xhr-post "http://racing-lagoon.info/nomu/translate.php" | |
`(:before ,text :level ,level :trans " 翻訳 ") | |
:encoding *encoding-utf8n* | |
:key #'xhr:xhr-response-text) | |
(whenlet tags (dom:find-node (dom::parse-html-string res) | |
(lambda (e) | |
(and (eq (dom:tag e) :textarea) | |
(equal (dom:attr e :name) "after")))) | |
(remove #\LFD (car (dom:contents (car tags))))))) | |
(defun user::nomurize-region (from to &optional (lv 2)) | |
(interactive "r") | |
(let ((nomu (nomurize (buffer-substring from to) lv))) | |
(if nomu (insert (format nil "~%~A~%" nomu)) | |
(message "failed nomurizing.")))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment