wok-next rev 8451

Add: emacs-pkg-text-translator
author Dominique Corbex <domcox@slitaz.org>
date Sun Feb 06 22:20:54 2011 +0100 (2011-02-06)
parents c57c251fb82b
children 79deaee814c4
files emacs-pkg-text-translator/receipt emacs-pkg-text-translator/stuff/90-text-translator-init.el emacs-pkg-text-translator/stuff/text-translator-load.el emacs-pkg-text-translator/stuff/text-translator-vars.el emacs-pkg-text-translator/stuff/text-translator.el emacs-pkg-vala-mode/stuff/80-vala-init.el
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/emacs-pkg-text-translator/receipt	Sun Feb 06 22:20:54 2011 +0100
     1.3 @@ -0,0 +1,36 @@
     1.4 +# SliTaz package receipt.
     1.5 +
     1.6 +PACKAGE="emacs-pkg-text-translator"
     1.7 +VERSION="0.6.6.1"
     1.8 +CATEGORY="development"
     1.9 +SHORT_DESC="Translates strings on Emacs by using translation services that exists on the Internet."
    1.10 +MAINTAINER="domcox@slitaz.org"
    1.11 +DEPENDS="emacs"
    1.12 +TARBALL="$PACKAGE-$VERSION.tar.gz"
    1.13 +WEB_SITE="http://d.hatena.ne.jp/khiker/20070503/emacs_text_translator"
    1.14 +TAGS="emacs"
    1.15 +
    1.16 +
    1.17 +# Rules to gen a SliTaz package suitable for Tazpkg.
    1.18 +genpkg_rules()
    1.19 +{
    1.20 +	echo -n "Installing text-translator"
    1.21 +	mkdir -p $fs/usr/share/emacs/site-lisp/text-translator && \
    1.22 +	cp stuff/text*.el $fs/usr/share/emacs/site-lisp/text-translator
    1.23 +	status
    1.24 +
    1.25 +	echo -n "Installing start file"
    1.26 +	mkdir -p $fs/usr/share/emacs/site-lisp/site-start.d && \
    1.27 +	cp stuff/90*.el $fs/usr/share/emacs/site-lisp/site-start.d
    1.28 +	status
    1.29 +}
    1.30 +
    1.31 +post_install()
    1.32 +{
    1.33 +	tazpkg reconfigure emacs
    1.34 +}
    1.35 +
    1.36 +post_remove()
    1.37 +{
    1.38 +	tazpkg reconfigure emacs
    1.39 +}
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/emacs-pkg-text-translator/stuff/90-text-translator-init.el	Sun Feb 06 22:20:54 2011 +0100
     2.3 @@ -0,0 +1,30 @@
     2.4 +;; Register
     2.5 +
     2.6 +(require 'text-translator)
     2.7 +
     2.8 +
     2.9 +;; set global key
    2.10 +
    2.11 +(global-set-key "\C-x\M-t" 'text-translator)
    2.12 +(global-set-key "\C-x\M-T" 'text-translator-translate-last-string)
    2.13 +;; translate all sites.
    2.14 +;; for example, if you specify "enja", text-translator use google.com_enja, yahoo.com_enja, ... .
    2.15 +(global-set-key "\C-x\M-a" 'text-translator-all)
    2.16 +
    2.17 +
    2.18 +;; add keys to major-mode
    2.19 +
    2.20 +(add-hook
    2.21 + 'text-translator-mode-hook
    2.22 + (lambda()
    2.23 +   ;; if you do not change prefix-key, it is executed by C-c M-a
    2.24 +   (define-key text-translator-mode-pkey-map "\M-a" 'text-translator-translate-recent-type)))
    2.25 +
    2.26 +
    2.27 +;; use proxy
    2.28 +
    2.29 +;; ;; if you are setting environment variables HTTP_PROXY,
    2.30 +;; ;; you have not to set this.
    2.31 +;; (setq text-translator-proxy-server "proxy.hogehoge.com")
    2.32 +;; (setq text-translator-proxy-port   8080)
    2.33 +
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/emacs-pkg-text-translator/stuff/text-translator-load.el	Sun Feb 06 22:20:54 2011 +0100
     3.3 @@ -0,0 +1,41 @@
     3.4 +;;; text-translator-load.el --- Text Translator
     3.5 +
     3.6 +;; Copyright (C) 2007-2009  khiker
     3.7 +
     3.8 +;; Author: khiker <khiker.mail+elisp@gmail.com>
     3.9 +;;         plus   <MLB33828@nifty.com>
    3.10 +
    3.11 +;; This file is free software; you can redistribute it and/or modify
    3.12 +;; it under the terms of the GNU General Public License as published by
    3.13 +;; the Free Software Foundation; either version 3, or (at your option)
    3.14 +;; any later version.
    3.15 +
    3.16 +;; This file is distributed in the hope that it will be useful,
    3.17 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
    3.18 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    3.19 +;; GNU General Public License for more details.
    3.20 +
    3.21 +;; You should have received a copy of the GNU General Public License
    3.22 +;; along with GNU Emacs; see the file COPYING.  If not, write to
    3.23 +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    3.24 +;; Boston, MA 02110-1301, USA.
    3.25 +
    3.26 +;;; Commentary:
    3.27 +
    3.28 +;; autoload for text-translator
    3.29 +
    3.30 +;;; Code:
    3.31 +
    3.32 +(autoload 'text-translator "text-translator" nil t)
    3.33 +(autoload 'text-translator-translate-last-string "text-translator" nil t)
    3.34 +(autoload 'text-translator-translate-by-auto-selection "text-translator" nil t)
    3.35 +(autoload 'text-translator-toggle-leave-string "text-translator" nil t)
    3.36 +(autoload 'text-translator-translate-recent-type "text-translator" nil t)
    3.37 +(autoload 'text-translator-translate-default "text-translator" nil t)
    3.38 +
    3.39 +(provide 'text-translator-load)
    3.40 +;;; text-translator-load.el ends here
    3.41 +
    3.42 +;; Local Variables:
    3.43 +;; Coding: iso-2022-7bit
    3.44 +;; End:
     4.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.2 +++ b/emacs-pkg-text-translator/stuff/text-translator-vars.el	Sun Feb 06 22:20:54 2011 +0100
     4.3 @@ -0,0 +1,454 @@
     4.4 +;;; text-translator-vars.el --- Text Translator
     4.5 +
     4.6 +;; Copyright (C) 2007-2010  khiker
     4.7 +
     4.8 +;; Author: khiker <khiker.mail+elisp@gmail.com>
     4.9 +;;         plus   <MLB33828@nifty.com>
    4.10 +
    4.11 +;; This file is free software; you can redistribute it and/or modify
    4.12 +;; it under the terms of the GNU General Public License as published by
    4.13 +;; the Free Software Foundation; either version 3, or (at your option)
    4.14 +;; any later version.
    4.15 +
    4.16 +;; This file is distributed in the hope that it will be useful,
    4.17 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.18 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.19 +;; GNU General Public License for more details.
    4.20 +
    4.21 +;; You should have received a copy of the GNU General Public License
    4.22 +;; along with GNU Emacs; see the file COPYING.  If not, write to
    4.23 +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    4.24 +;; Boston, MA 02110-1301, USA.
    4.25 +
    4.26 +;;; Commentary:
    4.27 +
    4.28 +;; Variables for text-translator
    4.29 +
    4.30 +;;; Code:
    4.31 +
    4.32 +(defconst text-translator-version "0.7.4"
    4.33 +  "version numbers of this version of text-translator")
    4.34 +
    4.35 +(defconst text-translator-buffer "*translated*"
    4.36 +  "Buffer name that displays translation result.")
    4.37 +
    4.38 +(defconst text-translator-mode-name "Translator"
    4.39 +  "Major mode name for displaying to mode line.")
    4.40 +
    4.41 +(defconst text-translator-work-buffer (concat " " text-translator-buffer)
    4.42 +  "Output Buffer name from translation site.")
    4.43 +
    4.44 +(defgroup text-translator nil
    4.45 +  "Text Translator"
    4.46 +  :tag "Text Translator"
    4.47 +  :group 'text-translator)
    4.48 +
    4.49 +(defcustom text-translator-prefix-key "\C-c"
    4.50 +  "*Prefix key for text-translator commands."
    4.51 +  :tag "Prefix Key of text-translator"
    4.52 +  :type '(string :size 10)
    4.53 +  :group 'text-translator)
    4.54 +
    4.55 +(defcustom text-translator-auto-window-adjust t
    4.56 +  "*Whether or not you adjust height of window displayed by dividing."
    4.57 +  :type  'boolean
    4.58 +  :group 'text-translator)
    4.59 +
    4.60 +(defcustom text-translator-window-min-height 4
    4.61 +  "*Specify minimum height of the translation result display buffer."
    4.62 +  :type  'integer
    4.63 +  :group 'text-translator)
    4.64 +
    4.65 +(defcustom text-translator-leave-string nil
    4.66 +  "*Whether or not you leave the character string before the translating."
    4.67 +  :type  'boolean
    4.68 +  :group 'text-translator)
    4.69 +
    4.70 +(defcustom text-translator-pre-string-replace-alist
    4.71 +  '(("+" . "+") ("&#8211;" . "-")  ("&#8226;" . "・"))
    4.72 +  "*Rule that converts character string that wants to translate."
    4.73 +  :type  '(repeat
    4.74 +           (cons :tag "Rule"
    4.75 +                 (string :tag "Letter before the converting.")
    4.76 +                 (string :tag "Letter after the converting.")))
    4.77 +  :group 'text-translator)
    4.78 +
    4.79 +(defcustom text-translator-post-string-replace-alist
    4.80 +  '(("\r" . "") ("&#39;" . "'") ("&quot;" . "\"")
    4.81 +    ("&amp;" . "&") ("&lt;" . "<") ("&gt;" . ">") ("&#8211;" . "-")
    4.82 +    ("&#264;" . "Ĉ") ("&#265;" . "ĉ") ("&#284;" . "Ĝ") ("&#285;" . "ĝ")
    4.83 +    ("&#292;" . "Ĥ") ("&#293;" . "ĥ") ("&#308;" . "Ĵ") ("&#309;" . "ĵ")
    4.84 +    ("&#348;" . "Ŝ") ("&#349;" . "ŝ") ("&#364;" . "Ŭ") ("&#365;" . "ŭ"))
    4.85 +  "*Rule that converts character string after the translation."
    4.86 +  :type  '(repeat
    4.87 +           (cons :tag "Rule"
    4.88 +                 (string :tag "Letter before the converting.")
    4.89 +                 (string :tag "Letter after the converting.")))
    4.90 +  :group 'text-translator)
    4.91 +
    4.92 +(defcustom text-translator-proxy-server
    4.93 +  (let ((proxy (or (getenv "HTTP_PROXY") "")))
    4.94 +    (and (string-match "^\\(http://\\)?\\(.+\\):\\([0-9]+\\)" proxy)
    4.95 +         (match-string 2 proxy)))
    4.96 +  "*Proxy server used."
    4.97 +  :type  '(choice (string :tag "specify proxy")
    4.98 +                  (const :tag "not use proxy" nil))
    4.99 +  :group 'text-translator)
   4.100 +
   4.101 +(defcustom text-translator-proxy-port
   4.102 +  (let ((proxy (or (getenv "HTTP_PROXY") "")))
   4.103 +    (or (and (string-match "^\\(http://\\)?\\(.+\\):\\([0-9]+\\)" proxy)
   4.104 +             (string-to-number (match-string 3 proxy)))
   4.105 +        8080))
   4.106 +  "*Proxy port number used."
   4.107 +  :type  'integer
   4.108 +  :group 'text-translator)
   4.109 +
   4.110 +(defcustom text-translator-proxy-user nil
   4.111 +  "*Basic proxy authorization user name."
   4.112 +  :type  '(choice (string :tag "Basic proxy authorization user name")
   4.113 +                  (const :tag "Not use Basic proxy authorization" nil))
   4.114 +  :group 'text-translator)
   4.115 +
   4.116 +(defcustom text-translator-proxy-password nil
   4.117 +  "*Basic proxy authorization password."
   4.118 +  :type  '(choice (string :tag "Basic proxy authorization password")
   4.119 +                  (const :tag "Not use Basic proxy authorization" nil))
   4.120 +  :group 'text-translator)
   4.121 +
   4.122 +(defcustom text-translator-site-data-template-alist
   4.123 +  '(;; Google.com
   4.124 +    ("google.com"
   4.125 +     "translate.google.com"
   4.126 +     "/ HTTP/1.1"
   4.127 +     "js=n&prev=_t&hl=ja&ie=UTF-8&text=%s&file=&sl=%o&tl=%t"
   4.128 +     utf-8-dos
   4.129 +     (lambda ()
   4.130 +       (text-translator-extract-tag-exclusion-string
   4.131 +        "<span id=result_box[^>]*>\\(\\(<span [^>]*>\\([^<]\\|<br>\\)*</span>\\)+\\)</span>"))
   4.132 +     (("en" . "ja") ("ja" . "en")
   4.133 +      ("en" . "es") ("es" . "en")
   4.134 +      ("en" . "fr") ("fr" . "en")
   4.135 +      ("en" . "de") ("de" . "en")
   4.136 +      ("en" . "it") ("it" . "en")
   4.137 +      ("en" . "ar") ("ar" . "en")
   4.138 +      ("de" . "fr") ("fr" . "de")
   4.139 +      ("en" . "pt") ("pt" . "en")
   4.140 +      ("en" . "ru") ("ru" . "en")
   4.141 +      ("en" . "ko") ("ko" . "en")
   4.142 +      ("en" . "zh-CN") ("zh-CN" . "en")
   4.143 +      ("en" . "zh-TW") ("zh-TW" . "en")
   4.144 +      ("zh-CN" . "zh-TW") ("zh-TW" . "zh-CN"))
   4.145 +     (("zh-TW" . "tw") ("zh-CN" . "ch")))
   4.146 +
   4.147 +    ;; Yahoo.com
   4.148 +    ("yahoo.com"
   4.149 +     "babelfish.yahoo.com"
   4.150 +     "/translate_txt HTTP/1.1"
   4.151 +     "ei=UTF-8&doit=done&intl=1&tt=urltext&trtext=%s&lp=%o_%t&btnTrTxt=Translate"
   4.152 +     utf-8
   4.153 +     "    <div id=\"result\"><div style=\"padding:0.6em;\">\\([^<]*\\)</div>"
   4.154 +     (("en" . "ja") ("ja" . "en")
   4.155 +      ("en" . "nl") ("nl" . "en")
   4.156 +      ("en" . "fr") ("fr" . "en")
   4.157 +      ("en" . "de") ("de" . "en")
   4.158 +      ("en" . "el") ("el" . "en")
   4.159 +      ("en" . "it") ("it" . "en")
   4.160 +      ("en" . "ko") ("ko" . "en")
   4.161 +      ("en" . "pt") ("pt" . "en")
   4.162 +      ("en" . "ru") ("ru" . "en")
   4.163 +      ("en" . "es") ("es" . "en")
   4.164 +      ("nl" . "fr")
   4.165 +      ("fr" . "de")
   4.166 +      ("fr" . "el") ("el" . "fr")
   4.167 +      ("fr" . "it") ("it" . "fr")
   4.168 +      ("fr" . "pt") ("pt" . "fr")
   4.169 +      ("fr" . "es") ("es" . "fr")
   4.170 +      ("en" . "zh") ("zh" . "en")
   4.171 +      ("en" . "zt") ("zt" . "en"))
   4.172 +     (("zh" . "ch") ("zt" . "tw")))
   4.173 +
   4.174 +    ;; Freetranslation.com
   4.175 +    ("freetranslation.com"
   4.176 +     "ets.freetranslation.com"
   4.177 +     "/ HTTP/1.1"
   4.178 +     "sequence=core&mode=html&charset=UTF-8&template=results_en-us.htm&language=%o/%t&srctext=%s"
   4.179 +     utf-8
   4.180 +     "<textarea name=\"dsttext\" cols=\"40\" rows=\"6\" style=\"width:99%;height:142px;\" id=\"resultsBox\">\\([^<]*\\)</textarea>"
   4.181 +     (("English" . "Spanish") ("Spanish" . "English")
   4.182 +      ("English" . "French")  ("French" . "English")
   4.183 +      ("English" . "German")  ("German" . "English")
   4.184 +      ("English" . "Italian") ("Italian" . "English")
   4.185 +      ("English" . "Dutch")   ("Dutch" . "English")
   4.186 +      ("English" . "Portuguese") ("Portuguese" . "English")
   4.187 +      ("English" . "Norwegian"))
   4.188 +     (("English" . "en") ("Spanish" . "es")
   4.189 +      ("French" . "fr") ("German" . "de")
   4.190 +      ("Italian" . "it") ("Dutch" . "nl")
   4.191 +      ("Portuguese" . "pt") ("Norwegian" . "no")))
   4.192 +    ("freetranslation.com"
   4.193 +     "ets6.freetranslation.com"
   4.194 +     "/ HTTP/1.1"
   4.195 +     "sequence=core&mode=html&charset=UTF-8&template=results_en-us.htm&language=%o/%t&srctext=%s"
   4.196 +     utf-8
   4.197 +     "<textarea name=\"dsttext\" cols=\"40\" rows=\"6\" style=\"width:99%;height:142px;\" id=\"resultsBox\">\\([^<]*\\)</textarea>"
   4.198 +     (("English" . "Russian") ("Russian" . "English")
   4.199 +      ("English" . "SimplifiedChinese")
   4.200 +      ("English" . "TraditionalChinese"))
   4.201 +     (("English" . "en") ("Russian" . "ru")
   4.202 +      ("SimplifiedChinese" . "ch") ("TraditionalChinese" . "tw")))
   4.203 +    ("freetranslation.com"
   4.204 +     "tets9.freetranslation.com"
   4.205 +     "/ HTTP/1.1"
   4.206 +     "sequence=core&mode=html&charset=UTF-8&template=results_en-us.htm&language=%o/%t&srctext=%s"
   4.207 +     utf-8
   4.208 +     "<textarea name=\"dsttext\" cols=\"40\" rows=\"6\" style=\"width:99%;height:142px;\" id=\"resultsBox\">\\([^<]*\\)</textarea>"
   4.209 +     (("English" . "Japanese") ("Japanese" . "English"))
   4.210 +     (("English" . "en") ("Japanese" . "ja")))
   4.211 +
   4.212 +    ;; Livedoor.com
   4.213 +    ("livedoor.com"
   4.214 +     "translate.livedoor.com"
   4.215 +     "/ HTTP/1.1"
   4.216 +     "clear_flg=1&src_text=%s&trns_type=%o,%t&sumit=翻訳"
   4.217 +     utf-8
   4.218 +     "<textarea name=\"tar_text\" cols=\"40\" rows=\"10\" wrap=\"physical\">\\([^<]*\\)</textarea>"
   4.219 +     (("1" . "2") ("2" . "1")
   4.220 +      ("2" . "9") ("9" . "2")
   4.221 +      ("2" . "6") ("6" . "2"))
   4.222 +     (("1" . "en") ("2" . "ja")
   4.223 +      ("6" . "ch") ("9" . "ko")))
   4.224 +
   4.225 +    ;; Fresheye.com
   4.226 +    ("fresheye.com"
   4.227 +     "mt.fresheye.com"
   4.228 +     "/ft_result.cgi HTTP/1.1"
   4.229 +     "gen_text=%s&e=%o%t"
   4.230 +     utf-8
   4.231 +     "<TEXTAREA class=\"out-form\" name=\"gen_text2\" cols=\"25\" rows=\"15\">\\([^<]*\\)</TEXTAREA>"
   4.232 +     (("E" . "J") ("J" . "E"))
   4.233 +     (("E" . "en") ("J" . "ja")))
   4.234 +    ("fresheye.com"
   4.235 +     "mt.fresheye.com"
   4.236 +     "/ft_cjresult.cgi HTTP/1.1"
   4.237 +     "gen_text=%s&charset=gb2312&cjjc=%o%t"
   4.238 +     utf-8
   4.239 +     "<TEXTAREA class=\"out-form\" name=\"gen_text2\" cols=\"25\" rows=\"15\">\\([^<]*\\)</TEXTAREA>"
   4.240 +     (("c" . "j") ("j" . "c") ("e" . "c"))
   4.241 +     (("c" . "ch") ("j" . "ja") ("e" . "en")))
   4.242 +    ("fresheye.com"
   4.243 +     "mt.fresheye.com"
   4.244 +     "/ft_cjresult.cgi HTTP/1.1"
   4.245 +     "gen_text=%s&charset=big5&cjjc=%o%t"
   4.246 +     utf-8
   4.247 +     "<TEXTAREA class=\"out-form\" name=\"gen_text2\" cols=\"25\" rows=\"15\">\\([^<]*\\)</TEXTAREA>"
   4.248 +     (("c" . "j") ("j" . "c") ("e" . "c"))
   4.249 +     (("c" . "tw") ("j" . "ja") ("e" . "en")))
   4.250 +
   4.251 +    ;; Excite.co.jp
   4.252 +    ("excite.co.jp"
   4.253 +     "www.excite.co.jp"
   4.254 +     "/world/english/ HTTP/1.1"
   4.255 +     "wb_lp=%o%t&before=%s"
   4.256 +     utf-8
   4.257 +     "<textarea name=\"after\" id=\"after\">\\([^<]*\\)</textarea>"
   4.258 +     (("EN" . "JA") ("JA" . "EN"))
   4.259 +     (("EN" . "en") ("JA" . "ja")))
   4.260 +    ("excite.co.jp"
   4.261 +     "www.excite.co.jp"
   4.262 +     "/world/chinese/ HTTP/1.1"
   4.263 +     "wb_lp=%o%t&before=%s"
   4.264 +     utf-8
   4.265 +     "<textarea name=\"after\" id=\"after\">\\([^<]*\\)</textarea>"
   4.266 +     (("JA" . "CH") ("CH" . "JA"))
   4.267 +     (("JA" . "ja") ("CH" . "ch")))
   4.268 +    ("excite.co.jp"
   4.269 +     "www.excite.co.jp"
   4.270 +     "/world/chinese/ HTTP/1.1"
   4.271 +     "wb_lp=%o%t&big5=yes&before=%s"
   4.272 +     utf-8
   4.273 +     "<textarea name=\"after\" id=\"after\">\\([^<]*\\)</textarea>"
   4.274 +     (("JA" . "CH") ("CH" . "JA"))
   4.275 +     (("JA" . "ja") ("CH" . "tw")))
   4.276 +    ("excite.co.jp"
   4.277 +     "www.excite.co.jp"
   4.278 +     "/world/korean/ HTTP/1.1"
   4.279 +     "wb_lp=%o%t&before=%s"
   4.280 +     utf-8
   4.281 +     "<textarea name=\"after\" id=\"after\">\\([^<]*\\)</textarea>"
   4.282 +     (("JA" . "KO") ("KO" . "JA"))
   4.283 +     (("JA" . "ja") ("KO" . "ko")))
   4.284 +
   4.285 +    ;; Yahoo.co.jp
   4.286 +    ("yahoo.co.jp"
   4.287 +     "honyaku.yahoo.co.jp"
   4.288 +     "/transtext HTTP/1.1"
   4.289 +     "both=TH&text=%s&clearFlg=1&eid=CR-%o%t"
   4.290 +     utf-8
   4.291 +     "<textarea rows=12 cols=30 name=\"trn_text\" id=\"trn_textText\" class=\"smaller\">\\([^<]*\\)</textarea>"
   4.292 +     (("E" . "J") ("J" . "E")
   4.293 +      ("C" . "J") ("J" . "C-CN")
   4.294 +      ("K" . "J") ("J" . "K"))
   4.295 +     (("E" . "en") ("J" . "ja")
   4.296 +      ("C" . "ch") ("C-CN" . "ch")
   4.297 +      ("K" . "ko")))
   4.298 +
   4.299 +    ;; Ocn.ne.jp
   4.300 +    ("ocn.ne.jp"
   4.301 +     "cgi01.ocn.ne.jp"
   4.302 +     "/cgi-bin/translation/index.cgi HTTP/1.1"
   4.303 +     "langpair=%o%t&sourceText=%s"
   4.304 +     utf-8
   4.305 +     "<TEXTAREA NAME=\"responseText\" ROWS=\"5\" COLS=\"41\" WRAP=\"virtual\" CLASS=\"in2\">\\([^<]*\\)</TEXTAREA>"
   4.306 +     (("en" . "ja") ("ja" . "en")
   4.307 +      ("ja" . "ko") ("ko" . "ja")
   4.308 +      ("ja" . "zh") ("zh" . "ja"))
   4.309 +     (("zh" . "ch"))))
   4.310 +  "The alist where setting of the site which is used for text translation is
   4.311 +described. To update site-data, evalute `text-translator-site-data-init`."
   4.312 +  :type '(repeat
   4.313 +          (list :tag "Web Site"
   4.314 +                (string :tag "Web site name and translation type")
   4.315 +                (string :tag "Host name")
   4.316 +                (string :tag "POST path and HTTP version")
   4.317 +                (string :tag "POST contents")
   4.318 +                (symbol :tag "Character code")
   4.319 +                (choice (string :tag "regexp") (symbol :tag "function"))
   4.320 +                (list :tag (concat "The correspondence of translation-able "
   4.321 +                                   "name (used by translation sites)"))
   4.322 +                (list :tag (concat "The correspondence of name that used by "
   4.323 +                                   "text-translator and name that used by "
   4.324 +                                   "translation sites"))))
   4.325 +  :group 'text-translator)
   4.326 +
   4.327 +(defcustom text-translator-site-data-minimum-alist
   4.328 +  '(;; lou5.jp (Japanese, Lou)
   4.329 +    ("lou5.jp_*normal"
   4.330 +     "lou5.jp"
   4.331 +     "/ HTTP/1.1"
   4.332 +     "v=1&text=%s"
   4.333 +     utf-8
   4.334 +     (lambda ()
   4.335 +       (text-translator-extract-tag-exclusion-string
   4.336 +        "<p class=\"large align-left box\">\\(\\(.\\|\n\\)*?\\)</p>"
   4.337 +        t)))
   4.338 +    ;; lou5.jp (Japanese, Lou Blog)
   4.339 +    ("lou5.jp_*blog"
   4.340 +     "lou5.jp"
   4.341 +     "/ HTTP/1.1"
   4.342 +     "v=2&text=%s"
   4.343 +     utf-8
   4.344 +     "<p class=\"large align-left box\">\\(\\(.\\|\n\\)*?\\)</p>")
   4.345 +
   4.346 +    ;; tatoeba.org (Furigana, romaji)
   4.347 +    ("tatoeba.org_furigana"
   4.348 +     "tatoeba.org"
   4.349 +     "/eng/tools/romaji_furigana?query=%s&type=furigana HTTP/1.1"
   4.350 +     nil
   4.351 +     utf-8
   4.352 +     "class=\"furigana\">\\(\\(.\\|\n\\)*?\\)</div><form id=\"ToolRomajiFuriganaForm")
   4.353 +    ("tatoeba.org_romaji"
   4.354 +     "tatoeba.org"
   4.355 +     "/eng/tools/romaji_furigana?query=%s&type=romaji HTTP/1.1"
   4.356 +     nil
   4.357 +     utf-8
   4.358 +     "class=\"furigana\">\\(\\(.\\|\n\\)*?\\)</div><form id=\"ToolRomajiFuriganaForm")
   4.359 +
   4.360 +    ;; traduku.net (Esperanto, English)
   4.361 +    ("traduku.net_eoen"
   4.362 +     "traduku.net"
   4.363 +     "/cgi-bin/traduku HTTP/1.0"
   4.364 +     "eo_en&t=%s"
   4.365 +     utf-8
   4.366 +     " id=\"rezulto\">\\(\\(.\\|\n\\)*?\\)</div>")
   4.367 +    ("traduku.net_eneo"
   4.368 +     "traduku.net"
   4.369 +     "/cgi-bin/traduku HTTP/1.0"
   4.370 +     "en_eo_trukilo&t=%s"
   4.371 +     utf-8
   4.372 +     " id=\"rezulto\">\\(\\(.\\|\n\\)*?\\)</div>"))
   4.373 +
   4.374 +  "*The alist where setting of the site which is used for text translation is
   4.375 +described. To update site-data, evalute `text-translator-site-data-init`."
   4.376 +  :type  '(repeat
   4.377 +           (list :tag "Web Site"
   4.378 +                 (string :tag "Web site name and translation type")
   4.379 +                 (string :tag "Host name")
   4.380 +                 (string :tag "POST path and HTTP version")
   4.381 +                 (string :tag "POST contents")
   4.382 +                 (symbol :tag "Character code")
   4.383 +                 (choice (string :tag "regexp") (symbol :tag "function"))))
   4.384 +  :group 'text-translator)
   4.385 +
   4.386 +;; text-translator-site-data-template-alist
   4.387 +;; + text-translator-site-data-minimum-alist
   4.388 +;; = text-translator-site-data-alist
   4.389 +(defvar text-translator-site-data-alist nil
   4.390 +  "The alist where setting of the site which is used for text translation is
   4.391 +described.")
   4.392 +
   4.393 +(defcustom text-translator-default-engine "google.com_enja"
   4.394 +  "*Translation engine used by default."
   4.395 +  :type  (cons 'radio
   4.396 +               (mapcar
   4.397 +                (lambda (x)
   4.398 +                  (list 'const (car x)))
   4.399 +                text-translator-site-data-alist))
   4.400 +  :group 'text-translator)
   4.401 +
   4.402 +(defcustom text-translator-user-agent
   4.403 +;;  "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4"
   4.404 +  "Mozilla/5.0 (Windows; U; Windows NT 5.0; ja; rv:1.9) Gecko/2008052906 Firefox/3.0"
   4.405 +  "*text-translator's User Agent. Default is Firefox."
   4.406 +  :type  'string
   4.407 +  :group 'text-translator)
   4.408 +
   4.409 +(defcustom text-translator-mode-hook nil
   4.410 +  "*Hook run at the end of function `text-translator-mode'."
   4.411 +  :type 'hook
   4.412 +  :group 'text-translator)
   4.413 +
   4.414 +(defcustom text-translator-auto-selection-func nil
   4.415 +  "*Value is function that select translation engine automatic.
   4.416 +this value is function for `text-translator-translate-by-auto-selection'."
   4.417 +  :type 'symbol
   4.418 +  :group 'text-translator)
   4.419 +
   4.420 +(defcustom text-translator-display-popup nil
   4.421 +  "*Non-nil means translated message is displayed by using popup-tip.
   4.422 +To use this option, you have to require popup.el.
   4.423 +popup.el URL: http://github.com/m2ym/auto-complete"
   4.424 +  :type 'symbol
   4.425 +  :group 'text-translator)
   4.426 +
   4.427 +(defcustom text-translator-do-fill-region nil
   4.428 +  "*Default is nil. if value is non-nil, it deletes
   4.429 +linefeed\\(and CR\\) from pre translation string(\"\\n\" -> \" \",
   4.430 +\"\r\" -> \"\"). and processing to straighten faces with
   4.431 +fill-paragraph after the translation. it is countermeasure
   4.432 +against the translation engines that processes per line."
   4.433 +  :type 'symbol
   4.434 +  :group 'text-translator)
   4.435 +
   4.436 +(defcustom text-translator-space-division-languages
   4.437 +  '("en" "es" "fr" "de" "it" "pt" "ru" "nl" "el" "no")
   4.438 +  "*List of language that word is delimited by blank."
   4.439 +  :type '(repeat (string :tag "language(2char)"))
   4.440 +  :group 'text-translator)
   4.441 +
   4.442 +(defvar text-translator-last-string ""
   4.443 +  "The last time, character string which was thrown to the translation site.")
   4.444 +
   4.445 +(defvar text-translator-engine-history nil
   4.446 +  "The history of translation engine which you used.")
   4.447 +
   4.448 +(defvar text-translator-search-regexp-or-func nil)
   4.449 +
   4.450 +(defvar text-translator-sitedata-hash nil)
   4.451 +
   4.452 +(provide 'text-translator-vars)
   4.453 +;;; text-translator-vars.el ends here
   4.454 +
   4.455 +;; Local Variables:
   4.456 +;; Coding: utf-8
   4.457 +;; End:
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/emacs-pkg-text-translator/stuff/text-translator.el	Sun Feb 06 22:20:54 2011 +0100
     5.3 @@ -0,0 +1,555 @@
     5.4 +;;; text-translator.el --- Text Translator
     5.5 +
     5.6 +;; Copyright (C) 2007-2010  khiker
     5.7 +
     5.8 +;; Author: khiker <khiker.mail+elisp@gmail.com>
     5.9 +;;         plus   <MLB33828@nifty.com>
    5.10 +
    5.11 +;; This file is free software; you can redistribute it and/or modify
    5.12 +;; it under the terms of the GNU General Public License as published by
    5.13 +;; the Free Software Foundation; either version 2, or (at your option)
    5.14 +;; any later version.
    5.15 +
    5.16 +;; This file is distributed in the hope that it will be useful,
    5.17 +;; but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.18 +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.19 +;; GNU General Public License for more details.
    5.20 +
    5.21 +;; You should have received a copy of the GNU General Public License
    5.22 +;; along with GNU Emacs; see the file COPYING.  If not, write to
    5.23 +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
    5.24 +;; Boston, MA 02110-1301, USA.
    5.25 +
    5.26 +;;; Commentary:
    5.27 +
    5.28 +;; Translates character strings on Emacs.
    5.29 +;; This package use the text translation service that exists on the internet.
    5.30 +
    5.31 +;; Read README.en (English) or README.ja (Japanese).
    5.32 +
    5.33 +;;; Code:
    5.34 +
    5.35 +(require 'text-translator-vars)
    5.36 +
    5.37 +(defun text-translator (arg &optional last engine-or-func)
    5.38 +  "The function which does text translation.
    5.39 +Use Excite, Google and so translation site.
    5.40 +1. Mark is active
    5.41 + - Prefix was supplied.
    5.42 +   1. Choose translation site which you use.
    5.43 +   2. Translate by type which you selected.
    5.44 + - Prefix was not supplied.
    5.45 +   Translate range of region that you selected by
    5.46 +   first element of `text-translator-engine-history'.
    5.47 +   (If `text-translator-engine-history' is nil,
    5.48 +    use `text-translator-default-engine'.)
    5.49 +2. Mark is deactive
    5.50 + - Prefix was supplied.
    5.51 +   1. Choose translation site which you use.
    5.52 +   2. Translate value which you input from minibuffer by type you selected.
    5.53 + - Prefix was not supplied.
    5.54 +   Translate value which you input from minibuffer by
    5.55 +   first element of `text-translator-engine-history'.
    5.56 +   (If `text-translator-engine-history' is nil,
    5.57 +    use `text-translator-default-engine'.)"
    5.58 +  (interactive "P")
    5.59 +  (add-to-list 'text-translator-engine-history text-translator-default-engine)
    5.60 +  (let ((minibuffer-history text-translator-engine-history)
    5.61 +        (engine (text-translator-check-valid-translation-engine
    5.62 +                 engine-or-func (car text-translator-engine-history)))
    5.63 +        str)
    5.64 +    ;; If prefix-arg is non-nil, change translation type.
    5.65 +    (when (or arg last)
    5.66 +      (setq engine (completing-read
    5.67 +                    (format "Select translation engine (default %s): " engine)
    5.68 +                    text-translator-site-data-alist nil t nil nil engine)))
    5.69 +    (setq str
    5.70 +          (cond
    5.71 +           (last
    5.72 +            text-translator-last-string)
    5.73 +           (t
    5.74 +            (text-translator-region-or-read-string
    5.75 +             (format "Enter string translated by %s: " engine)))))
    5.76 +    (text-translator-client
    5.77 +     (text-translator-check-valid-translation-engine
    5.78 +      (and (functionp engine-or-func) (funcall engine-or-func engine str))
    5.79 +      engine)
    5.80 +     str)))
    5.81 +
    5.82 +(defun text-translator-translate-by-auto-selection (arg)
    5.83 +  "Function that translates by auto selection of translation engine.
    5.84 +Function that select automatically is value of `text-translator-auto-selection-func'."
    5.85 +  (interactive "P")
    5.86 +  (text-translator arg nil text-translator-auto-selection-func))
    5.87 +
    5.88 +(defun text-translator-translate-by-auto-selection-enja (engine str)
    5.89 +  "Automatic selection function for English to Japanese(or Japanese to English)
    5.90 +translation.
    5.91 +If alphabet ratio is over 40%, select engine which is translating from English to Japanese.
    5.92 +Otherwise, from Japanese to English."
    5.93 +  (setq str (or str ""))
    5.94 +  (format
    5.95 +   "%s_%s"
    5.96 +   (text-translator-get-engine-type-or-site engine t)
    5.97 +   (if (> (/ (* (length (replace-regexp-in-string "[^A-Za-z]+" "" str)) 100)
    5.98 +             (length str))
    5.99 +          40)
   5.100 +       "enja" "jaen")))
   5.101 +
   5.102 +(defun text-translator-translate-last-string ()
   5.103 +  "The function to translate in the translation site that
   5.104 +I choose with the character string that I translated in the last time."
   5.105 +  (interactive)
   5.106 +  (text-translator nil t))
   5.107 +
   5.108 +
   5.109 +(defun text-translator-region-or-read-string (&optional prompt)
   5.110 +  "If mark is active, return the region, otherwise, read string with PROMPT."
   5.111 +  (cond
   5.112 +   (mark-active
   5.113 +    (buffer-substring-no-properties (region-beginning) (region-end)))
   5.114 +   (t
   5.115 +    (read-string (or prompt "Enter string: ")))))
   5.116 +
   5.117 +(defun text-translator-all (arg &optional key str)
   5.118 +  "The function to translate in all of translate sites that matches
   5.119 +the selected type."
   5.120 +  (interactive "P")
   5.121 +  (let ((hash text-translator-sitedata-hash)
   5.122 +        keys)
   5.123 +    (setq str (or str (text-translator-region-or-read-string)))
   5.124 +    (when (or (null hash)
   5.125 +              arg)
   5.126 +      (setq text-translator-sitedata-hash
   5.127 +            (text-translator-update-hashtable))
   5.128 +      (setq hash text-translator-sitedata-hash))
   5.129 +    (maphash '(lambda (x y)
   5.130 +                (setq keys (cons x keys)))
   5.131 +             hash)
   5.132 +    (setq key (or key (completing-read "Select type: " keys nil t)))
   5.133 +    (when key
   5.134 +      (save-selected-window
   5.135 +        (pop-to-buffer text-translator-buffer)
   5.136 +        (setq buffer-read-only nil)
   5.137 +        (erase-buffer)
   5.138 +        (text-translator-mode))
   5.139 +      (let ((sites (gethash key hash)))
   5.140 +        (setq text-translator-last-string str)
   5.141 +        (setq text-translator-search-regexp-or-func
   5.142 +              (concat "_" key))
   5.143 +        (dolist  (i sites)
   5.144 +          (text-translator-client i str t))))))
   5.145 +
   5.146 +(defun text-translator-all-by-auto-selection (arg)
   5.147 +  "The function to translate in all of translate sites, whose translation engine is selected automatically.
   5.148 +The selection function is the value of `text-translator-auto-selection-func'."
   5.149 +  (interactive "P")
   5.150 +  (let ((str (text-translator-region-or-read-string)))
   5.151 +    (text-translator-all
   5.152 +     arg
   5.153 +     (substring (funcall text-translator-auto-selection-func "" str) 1)
   5.154 +     str)))
   5.155 +
   5.156 +(defun text-translator-client (engine str &optional all)
   5.157 +  "Function that throws out words and phrases that want to translate into
   5.158 +specified site, and receives translation result."
   5.159 +  (let* ((history-delete-duplicates t)
   5.160 +         (buf (cond (all
   5.161 +                     (concat text-translator-work-buffer
   5.162 +                             (replace-regexp-in-string "_.*"
   5.163 +                                                       ""
   5.164 +                                                       engine)))
   5.165 +                    (t
   5.166 +                     text-translator-work-buffer)))
   5.167 +         (alist
   5.168 +          (cond
   5.169 +           ((not text-translator-do-fill-region)
   5.170 +            text-translator-pre-string-replace-alist)
   5.171 +           ;; for example, if engine is "excite.co.jp_enja",
   5.172 +           ;; this code returns "en".
   5.173 +           ((member (substring
   5.174 +                     (text-translator-get-engine-type-or-site engine) 0 2)
   5.175 +                    text-translator-space-division-languages)
   5.176 +            ;; replace "\n" to " ".
   5.177 +            (append '(("\n" . " ") ("\r" . ""))
   5.178 +                    text-translator-pre-string-replace-alist))
   5.179 +           (t
   5.180 +            ;; replace "\n" to "".
   5.181 +            (append '(("\n" . "") ("\r" . ""))
   5.182 +                    text-translator-pre-string-replace-alist))))
   5.183 +         (str (text-translator-replace-string str alist))
   5.184 +         (type (assoc engine text-translator-site-data-alist))
   5.185 +         (proc (open-network-stream "Web Connection" buf
   5.186 +                                    (or text-translator-proxy-server
   5.187 +                                        (nth 1 type))
   5.188 +                                    (or (and text-translator-proxy-server
   5.189 +                                             text-translator-proxy-port)
   5.190 +                                        80)))
   5.191 +         ;;(process-connection-type nil)
   5.192 +         (enc-str (text-translator-url-encode-string str (nth 4 type)))
   5.193 +         (post-str (if (nth 3 type) (format (nth 3 type) enc-str) nil))
   5.194 +         (truncate-partial-width-windows nil))
   5.195 +    (unless all
   5.196 +      (add-to-history 'text-translator-engine-history engine)
   5.197 +      (setq text-translator-search-regexp-or-func (nth 5 type))
   5.198 +      (setq text-translator-last-string str))
   5.199 +    (with-current-buffer (get-buffer-create buf)
   5.200 +      (erase-buffer)
   5.201 +      (set-process-coding-system proc (nth 4 type) 'binary)
   5.202 +      (set-process-filter proc 'text-translator-client-filter)
   5.203 +      (process-send-string
   5.204 +       proc
   5.205 +       (concat
   5.206 +        (cond
   5.207 +         (post-str
   5.208 +          ;; use POST method
   5.209 +          (concat "POST " (nth 2 type) "\r\n"))
   5.210 +         (t
   5.211 +          ;; use GET method
   5.212 +          (concat "GET " (format (nth 2 type) enc-str) "\r\n")))
   5.213 +        (and text-translator-proxy-server
   5.214 +             text-translator-proxy-user
   5.215 +             text-translator-proxy-password
   5.216 +             (format "Proxy-Authorization: Basic %s \r\n"
   5.217 +                     (base64-encode-string
   5.218 +                      (concat text-translator-proxy-user ":"
   5.219 +                              text-translator-proxy-password))))
   5.220 +        "HOST: " (nth 1 type) "\r\n"
   5.221 +        "User-Agent: " text-translator-user-agent "\r\n"
   5.222 +;;        "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5" "\r\n"
   5.223 +;;        "Accept-Language: ja,en-us;q=0.7,en;q=0.3" "\r\n"
   5.224 +        "Accept-Encoding: identity\r\n"
   5.225 +        "Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\r\n"
   5.226 +        "Keep-Alive: 300" "\r\n"
   5.227 +        "Connection: keep-alive" "\r\n"
   5.228 +        (when post-str
   5.229 +          (concat
   5.230 +           "Content-Type: application/x-www-form-urlencoded\r\n"
   5.231 +           "Content-Length: "
   5.232 +           (number-to-string (string-bytes post-str)) "\r\n"
   5.233 +           "\r\n"
   5.234 +           post-str "\r\n"))
   5.235 +        "\r\n"))
   5.236 +      (message "Translating...")
   5.237 +      (unless (or all
   5.238 +                  text-translator-display-popup)
   5.239 +        (save-selected-window
   5.240 +          (pop-to-buffer text-translator-buffer)
   5.241 +          (setq buffer-read-only nil)
   5.242 +          (erase-buffer)
   5.243 +          (text-translator-mode)
   5.244 +          (setq mode-line-buffer-identification
   5.245 +                `("%b [" ,(car text-translator-engine-history) "]")))))))
   5.246 +
   5.247 +(defun text-translator-client-filter (proc str)
   5.248 +  (let ((regex-or-func text-translator-search-regexp-or-func)
   5.249 +        bname all-flag)
   5.250 +    (with-current-buffer (process-buffer proc)
   5.251 +      (goto-char (process-mark proc))
   5.252 +      (insert (format "%s" str))
   5.253 +      (set-marker (process-mark proc) (point))
   5.254 +      (setq bname (buffer-name))
   5.255 +      (setq all-flag (not (string= bname text-translator-work-buffer)))
   5.256 +      (when all-flag
   5.257 +        (setq regex-or-func
   5.258 +              (nth 5
   5.259 +                   (assoc (concat
   5.260 +                           (substring bname
   5.261 +                                      (length text-translator-work-buffer)
   5.262 +                                      (length bname))
   5.263 +                           regex-or-func)
   5.264 +                          text-translator-site-data-alist))))
   5.265 +      (setq str (text-translator-replace-string
   5.266 +                 (or (cond
   5.267 +                      ((functionp regex-or-func)
   5.268 +                       (funcall regex-or-func))
   5.269 +                      ((re-search-backward regex-or-func nil t)
   5.270 +                       (match-string 1)))
   5.271 +                     "")
   5.272 +                 text-translator-post-string-replace-alist))
   5.273 +      (unless (string= "" str)
   5.274 +        (delete-process proc)
   5.275 +        (setq bname (buffer-name))
   5.276 +        (setq all-flag (not (string= bname text-translator-work-buffer)))
   5.277 +        (when (or all-flag
   5.278 +                  (not text-translator-display-popup))
   5.279 +          (text-translator-display-window str bname all-flag))))
   5.280 +    ;; To display in popup-tip, buffer is out of with-current-buffer.
   5.281 +    (when (and (not (string= "" str))
   5.282 +               (not all-flag)
   5.283 +               (fboundp 'popup-tip)
   5.284 +               (eq text-translator-display-popup t))
   5.285 +      (text-translator-display-popup str))))
   5.286 +
   5.287 +(defun text-translator-display-window (str buf all-flag)
   5.288 +  (let ((window (get-buffer-window text-translator-buffer))
   5.289 +        (window-min-height
   5.290 +         (if (> text-translator-window-min-height (/ (frame-height) 2))
   5.291 +             (/ (frame-height) 2)
   5.292 +           (1+ text-translator-window-min-height))))
   5.293 +    (set-buffer text-translator-buffer)
   5.294 +    (setq buffer-read-only nil)
   5.295 +    (cond
   5.296 +     (all-flag
   5.297 +      (insert (concat
   5.298 +               (propertize
   5.299 +                (format "-----  %s  -----\n"
   5.300 +                        (substring buf
   5.301 +                                   (length text-translator-work-buffer)
   5.302 +                                   (length buf)))
   5.303 +                'face font-lock-keyword-face)
   5.304 +               str "\n\n")))
   5.305 +     (t (when text-translator-leave-string
   5.306 +          (insert
   5.307 +           (concat
   5.308 +            (propertize "-----   Original  -----\n"
   5.309 +                        'face font-lock-keyword-face)
   5.310 +            text-translator-last-string
   5.311 +            "\n\n"
   5.312 +            (propertize "***** Translation *****\n"
   5.313 +                        'face font-lock-keyword-face))))
   5.314 +        (insert (concat str "\n"))
   5.315 +        (when text-translator-do-fill-region
   5.316 +          (goto-char (- (point) (/ (length str) 2)))
   5.317 +          (call-interactively 'fill-paragraph))
   5.318 +        (set-buffer-modified-p nil)
   5.319 +        ;; adjust window height
   5.320 +        (when (and text-translator-auto-window-adjust
   5.321 +                   (window-live-p window))
   5.322 +          (balance-windows)
   5.323 +          (shrink-window-if-larger-than-buffer window))
   5.324 +        (message "") ; prevent minibuffer from becoming two line.
   5.325 +        (ding)
   5.326 +        (message "Translating...done")))))
   5.327 +
   5.328 +(defun text-translator-display-popup (str)
   5.329 +  (let ((read-only-p buffer-read-only))
   5.330 +    (setq str (with-temp-buffer
   5.331 +                (insert str)
   5.332 +                (when text-translator-do-fill-region
   5.333 +                  (goto-char (- (point) (/ (length str) 2)))
   5.334 +                  (call-interactively 'fill-paragraph))
   5.335 +                (buffer-string)))
   5.336 +    (ding)
   5.337 +    (message "Translating...done")
   5.338 +    (if read-only-p
   5.339 +        ;; temporay cancel buffer-read-only
   5.340 +        (unwind-protect (progn
   5.341 +                          (setq buffer-read-only nil)
   5.342 +                          (popup-tip str :margin t))
   5.343 +          (setq buffer-read-only t))
   5.344 +      (popup-tip str :margin t))))
   5.345 +
   5.346 +(defun text-translator-update-hashtable ()
   5.347 +  (let ((hash (make-hash-table :test 'equal)))
   5.348 +    (mapc '(lambda (x)
   5.349 +             (let ((matched (replace-regexp-in-string "\\([^_]*\\)_"
   5.350 +                                                      ""
   5.351 +                                                      (car x))))
   5.352 +               (unless (or (string= (car x) matched)
   5.353 +                           (eq ?* (aref matched 0)))
   5.354 +                 (cond
   5.355 +                  ((gethash matched hash)
   5.356 +                   (puthash matched
   5.357 +                            (cons (car x) (gethash matched hash))
   5.358 +                            hash))
   5.359 +                  (t
   5.360 +                   (puthash matched (list (car x)) hash))))))
   5.361 +          text-translator-site-data-alist)
   5.362 +    hash))
   5.363 +
   5.364 +(defun text-translator-replace-string (str replace)
   5.365 +  "Function that converts character string specified for argument STR
   5.366 +according to rule REPLACE."
   5.367 +  (with-temp-buffer
   5.368 +    (insert str)
   5.369 +    ;; convert unusable string
   5.370 +    (format-replace-strings replace)
   5.371 +    (buffer-string)))
   5.372 +
   5.373 +(defun text-translator-extract-tag-exclusion-string (regex &optional dont-convert-br)
   5.374 +;;  (when (re-search-backward regex nil t)
   5.375 +  (when (re-search-backward regex nil t)
   5.376 +    ;; first: convert <br> tag to '\n' (when variable dont-convert-br is nil)
   5.377 +    ;; second: convert any another tags to empty string.
   5.378 +    (let ((matchstr (match-string 1)))
   5.379 +      (setq matchstr
   5.380 +            (text-translator-replace-string
   5.381 +             matchstr
   5.382 +             text-translator-post-string-replace-alist))
   5.383 +      (replace-regexp-in-string
   5.384 +       "<.*?>" "" (if dont-convert-br
   5.385 +                      matchstr
   5.386 +                    (replace-regexp-in-string
   5.387 +                     "<[bB][rR]\\( /\\)?>" "\n" matchstr))))))
   5.388 +
   5.389 +;;;; major-mode text-translator-mode
   5.390 +
   5.391 +;; variables for major mode
   5.392 +(defvar text-translator-mode nil)
   5.393 +(defvar text-translator-mode-map nil)
   5.394 +(defvar text-translator-mode-pkey-map nil)
   5.395 +(defvar text-translator-mode-syntax-table nil)
   5.396 +(defvar text-translator-mode-abbrev-table nil)
   5.397 +(define-abbrev-table 'text-translator-mode-abbrev-table ())
   5.398 +
   5.399 +;; keymap definition
   5.400 +(unless text-translator-mode-map
   5.401 +  (setq text-translator-mode-map (make-sparse-keymap))
   5.402 +  (define-prefix-command 'text-translator-mode-pkey-map)
   5.403 +  (let ((map text-translator-mode-pkey-map))
   5.404 +    (define-key map "\C-q" 'text-translator-quit)
   5.405 +    (define-key map "\C-a" 'text-translator-translate-recent-type)
   5.406 +    (define-key map "\C-l" 'text-translator-display-last-string)
   5.407 +    (define-key map "\C-d" 'text-translator-translate-default)
   5.408 +    (define-key map "\C-s" 'text-translator-toggle-leave-string)))
   5.409 +
   5.410 +;; major-mode
   5.411 +(defun text-translator-mode ()
   5.412 +  "Major mode for text-translator."
   5.413 +  (kill-all-local-variables)
   5.414 +  (setq local-abbrev-table text-translator-mode-abbrev-table)
   5.415 +  (set-syntax-table text-translator-mode-syntax-table)
   5.416 +  (setq mode-name text-translator-mode-name)
   5.417 +  (setq major-mode 'text-translator-mode)
   5.418 +  (define-key text-translator-mode-map
   5.419 +    text-translator-prefix-key text-translator-mode-pkey-map)
   5.420 +  (use-local-map text-translator-mode-map)
   5.421 +  (run-hooks 'text-translator-mode-hook))
   5.422 +
   5.423 +;; syntax-table
   5.424 +(unless text-translator-mode-syntax-table
   5.425 +  (setq text-translator-mode-syntax-table (make-syntax-table)))
   5.426 +
   5.427 +;; functions for major-mode
   5.428 +(defun text-translator-quit ()
   5.429 +  "Function that closes buffer for text-translator.
   5.430 +If window only have *translated* buffer, change another buffer."
   5.431 +  (interactive)
   5.432 +  (bury-buffer)
   5.433 +  (unless (one-window-p)
   5.434 +    (delete-window)))
   5.435 +
   5.436 +(defun text-translator-toggle-leave-string ()
   5.437 +  "Function that change value of `text-translator-leave-string'.
   5.438 +Toggle to display a translation result buffer of character
   5.439 +string that used last time."
   5.440 +  (interactive)
   5.441 +  (setq text-translator-leave-string (not text-translator-leave-string))
   5.442 +  (message "Pretranslational string switched %s to leave."
   5.443 +           (if text-translator-leave-string "" " not")))
   5.444 +
   5.445 +(defun text-translator-display-last-string (arg)
   5.446 +  "Function that displays translated character string last time.
   5.447 +Default display to minibuffer.
   5.448 +With prefix-arg, insert buffer."
   5.449 +  (interactive "P")
   5.450 +  (if arg
   5.451 +      (insert text-translator-last-string)
   5.452 +    (message "%s" text-translator-last-string)))
   5.453 +
   5.454 +(defun text-translator-translate-recent-type ()
   5.455 +  "Function that translates by type corresponding to the language
   5.456 +that used last time.
   5.457 +For example, last time, if you have used excite.co.jp_enja,
   5.458 +this time select from **_enja, and, translates."
   5.459 +  (interactive)
   5.460 +  (let* ((minibuffer-history text-translator-engine-history)
   5.461 +         (engine (car text-translator-engine-history))
   5.462 +         (last-type
   5.463 +          (concat "_" (text-translator-get-engine-type-or-site engine)))
   5.464 +         (type (completing-read
   5.465 +                (format "Select translation engine (last %s): " engine)
   5.466 +                (delq nil
   5.467 +                      (mapcar
   5.468 +                       (lambda (x)
   5.469 +                         (when (string-match last-type (car x))
   5.470 +                           x))
   5.471 +                       text-translator-site-data-alist))
   5.472 +                nil t)))
   5.473 +    (unless (string= "" type)
   5.474 +      (text-translator-client type text-translator-last-string))))
   5.475 +
   5.476 +(defun text-translator-translate-default ()
   5.477 +  "Function that translates by default type only.
   5.478 +Default is value of `text-translator-default-engine'."
   5.479 +  (interactive)
   5.480 +  (text-translator nil nil text-translator-default-engine))
   5.481 +
   5.482 +(defun text-translator-check-valid-translation-engine (engine valid-engine)
   5.483 +  "Check ENGINE that is registered in `text-translator-site-data-alist'.
   5.484 +Return ENGINE if it is already registered, otherwise return VALID-ENGINE."
   5.485 +  (or (car (member engine (mapcar 'car text-translator-site-data-alist)))
   5.486 +      valid-engine))
   5.487 +
   5.488 +(defun text-translator-get-engine-type-or-site (engine &optional get-site)
   5.489 +  "Get a translation engine type or site name.
   5.490 +If optional argument GET-SITE is nil, return a translation engine type.
   5.491 +Otherwise return a translation site name."
   5.492 +  (nth (if get-site 0 1) (split-string engine "_")))
   5.493 +
   5.494 +;; by google2.el
   5.495 +(defun text-translator-url-encode-string (str &optional coding)
   5.496 +  (apply (function concat)
   5.497 +         (mapcar
   5.498 +          (lambda (ch)
   5.499 +            (cond
   5.500 +             ((eq ch ?\n)               ; newline
   5.501 +              "%0D%0A")
   5.502 +             ((string-match "[-a-zA-Z0-9_:/]" (char-to-string ch)) ; xxx?
   5.503 +              (char-to-string ch))      ; printable
   5.504 +             ((char-equal ch ?\x20)     ; space
   5.505 +              "+")
   5.506 +             (t
   5.507 +              (format "%%%02X" ch))))   ; escape
   5.508 +          ;; Coerce a string to a list of chars.
   5.509 +          (append (encode-coding-string (or str "") (or coding 'iso-2022-jp))
   5.510 +                  nil))))
   5.511 +
   5.512 +;; initialization function
   5.513 +(defun text-translator-site-data-init ()
   5.514 +  ;; initialize
   5.515 +  (setq text-translator-site-data-alist nil)
   5.516 +  (setq text-translator-site-data-alist
   5.517 +        text-translator-site-data-minimum-alist)
   5.518 +  (dolist (site text-translator-site-data-template-alist)
   5.519 +    (let ((tt-convert-name '(lambda (lang)
   5.520 +                            (let ((match-lang (assoc lang
   5.521 +                                                     (nth 7 site))))
   5.522 +                              (if match-lang
   5.523 +                                  (cdr match-lang)
   5.524 +                                lang))))
   5.525 +        (tt-replace-string '(lambda (pstr olang tlang)
   5.526 +                              (when olang
   5.527 +                                (setq pstr
   5.528 +                                    (replace-regexp-in-string "%o"
   5.529 +                                                              olang
   5.530 +                                                              pstr)))
   5.531 +                              (when tlang
   5.532 +                                (setq pstr
   5.533 +                                    (replace-regexp-in-string "%t"
   5.534 +                                                              tlang
   5.535 +                                                              pstr))
   5.536 +                                pstr)))
   5.537 +        tt-alist)
   5.538 +    (dolist (i (nth 6 site))
   5.539 +      (add-to-list 'text-translator-site-data-alist
   5.540 +                   (list (format "%s"
   5.541 +                                 (concat (nth 0 site)
   5.542 +                                         "_"
   5.543 +                                         (funcall tt-convert-name (car i))
   5.544 +                                         (funcall tt-convert-name (cdr i))))
   5.545 +                         (nth 1 site)
   5.546 +                         (nth 2 site)
   5.547 +                         (funcall tt-replace-string
   5.548 +                                  (nth 3 site) (car i) (cdr i))
   5.549 +                         (nth 4 site)
   5.550 +                         (nth 5 site)))))))
   5.551 +(text-translator-site-data-init)        ; init
   5.552 +
   5.553 +(provide 'text-translator)
   5.554 +;;; text-translator.el ends here
   5.555 +
   5.556 +;; Local Variables:
   5.557 +;; Coding: utf-8
   5.558 +;; End:
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/emacs-pkg-vala-mode/stuff/80-vala-init.el	Sun Feb 06 22:20:54 2011 +0100
     6.3 @@ -0,0 +1,5 @@
     6.4 +;; Register vala-mode
     6.5 +
     6.6 +(autoload 'vala-mode "vala-mode" "Major mode for editing Vala code." t)
     6.7 +(add-to-list 'auto-mode-alist '("\\.vala$" . vala-mode))
     6.8 +(add-to-list 'auto-mode-alist '("\\.vapi$" . vala-mode))