Skip to content

Instantly share code, notes, and snippets.

@youz
Created May 10, 2011 13:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save youz/964463 to your computer and use it in GitHub Desktop.
Save youz/964463 to your computer and use it in GitHub Desktop.
ライトニング・リーズィョンルブルム間隙の氷結界の文章をノムリッシュローカライズします (リージョン内の文章をノムリッシュ翻訳します)
;;; -*- 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