# HG changeset patch # User Dominique Corbex # Date 1297027254 -3600 # Node ID 7935aa4dacbee9be786a5a0ee118e421536c9a5e # Parent c57c251fb82bebf429dcb8643a30f42fa38ae271 Add: emacs-pkg-text-translator diff -r c57c251fb82b -r 7935aa4dacbe emacs-pkg-text-translator/receipt --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emacs-pkg-text-translator/receipt Sun Feb 06 22:20:54 2011 +0100 @@ -0,0 +1,36 @@ +# SliTaz package receipt. + +PACKAGE="emacs-pkg-text-translator" +VERSION="0.6.6.1" +CATEGORY="development" +SHORT_DESC="Translates strings on Emacs by using translation services that exists on the Internet." +MAINTAINER="domcox@slitaz.org" +DEPENDS="emacs" +TARBALL="$PACKAGE-$VERSION.tar.gz" +WEB_SITE="http://d.hatena.ne.jp/khiker/20070503/emacs_text_translator" +TAGS="emacs" + + +# Rules to gen a SliTaz package suitable for Tazpkg. +genpkg_rules() +{ + echo -n "Installing text-translator" + mkdir -p $fs/usr/share/emacs/site-lisp/text-translator && \ + cp stuff/text*.el $fs/usr/share/emacs/site-lisp/text-translator + status + + echo -n "Installing start file" + mkdir -p $fs/usr/share/emacs/site-lisp/site-start.d && \ + cp stuff/90*.el $fs/usr/share/emacs/site-lisp/site-start.d + status +} + +post_install() +{ + tazpkg reconfigure emacs +} + +post_remove() +{ + tazpkg reconfigure emacs +} diff -r c57c251fb82b -r 7935aa4dacbe emacs-pkg-text-translator/stuff/90-text-translator-init.el --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emacs-pkg-text-translator/stuff/90-text-translator-init.el Sun Feb 06 22:20:54 2011 +0100 @@ -0,0 +1,30 @@ +;; Register + +(require 'text-translator) + + +;; set global key + +(global-set-key "\C-x\M-t" 'text-translator) +(global-set-key "\C-x\M-T" 'text-translator-translate-last-string) +;; translate all sites. +;; for example, if you specify "enja", text-translator use google.com_enja, yahoo.com_enja, ... . +(global-set-key "\C-x\M-a" 'text-translator-all) + + +;; add keys to major-mode + +(add-hook + 'text-translator-mode-hook + (lambda() + ;; if you do not change prefix-key, it is executed by C-c M-a + (define-key text-translator-mode-pkey-map "\M-a" 'text-translator-translate-recent-type))) + + +;; use proxy + +;; ;; if you are setting environment variables HTTP_PROXY, +;; ;; you have not to set this. +;; (setq text-translator-proxy-server "proxy.hogehoge.com") +;; (setq text-translator-proxy-port 8080) + diff -r c57c251fb82b -r 7935aa4dacbe emacs-pkg-text-translator/stuff/text-translator-load.el --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emacs-pkg-text-translator/stuff/text-translator-load.el Sun Feb 06 22:20:54 2011 +0100 @@ -0,0 +1,41 @@ +;;; text-translator-load.el --- Text Translator + +;; Copyright (C) 2007-2009 khiker + +;; Author: khiker +;; plus + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; autoload for text-translator + +;;; Code: + +(autoload 'text-translator "text-translator" nil t) +(autoload 'text-translator-translate-last-string "text-translator" nil t) +(autoload 'text-translator-translate-by-auto-selection "text-translator" nil t) +(autoload 'text-translator-toggle-leave-string "text-translator" nil t) +(autoload 'text-translator-translate-recent-type "text-translator" nil t) +(autoload 'text-translator-translate-default "text-translator" nil t) + +(provide 'text-translator-load) +;;; text-translator-load.el ends here + +;; Local Variables: +;; Coding: iso-2022-7bit +;; End: diff -r c57c251fb82b -r 7935aa4dacbe emacs-pkg-text-translator/stuff/text-translator-vars.el --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emacs-pkg-text-translator/stuff/text-translator-vars.el Sun Feb 06 22:20:54 2011 +0100 @@ -0,0 +1,454 @@ +;;; text-translator-vars.el --- Text Translator + +;; Copyright (C) 2007-2010 khiker + +;; Author: khiker +;; plus + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 3, or (at your option) +;; any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; Variables for text-translator + +;;; Code: + +(defconst text-translator-version "0.7.4" + "version numbers of this version of text-translator") + +(defconst text-translator-buffer "*translated*" + "Buffer name that displays translation result.") + +(defconst text-translator-mode-name "Translator" + "Major mode name for displaying to mode line.") + +(defconst text-translator-work-buffer (concat " " text-translator-buffer) + "Output Buffer name from translation site.") + +(defgroup text-translator nil + "Text Translator" + :tag "Text Translator" + :group 'text-translator) + +(defcustom text-translator-prefix-key "\C-c" + "*Prefix key for text-translator commands." + :tag "Prefix Key of text-translator" + :type '(string :size 10) + :group 'text-translator) + +(defcustom text-translator-auto-window-adjust t + "*Whether or not you adjust height of window displayed by dividing." + :type 'boolean + :group 'text-translator) + +(defcustom text-translator-window-min-height 4 + "*Specify minimum height of the translation result display buffer." + :type 'integer + :group 'text-translator) + +(defcustom text-translator-leave-string nil + "*Whether or not you leave the character string before the translating." + :type 'boolean + :group 'text-translator) + +(defcustom text-translator-pre-string-replace-alist + '(("+" . "+") ("–" . "-") ("•" . "・")) + "*Rule that converts character string that wants to translate." + :type '(repeat + (cons :tag "Rule" + (string :tag "Letter before the converting.") + (string :tag "Letter after the converting."))) + :group 'text-translator) + +(defcustom text-translator-post-string-replace-alist + '(("\r" . "") ("'" . "'") (""" . "\"") + ("&" . "&") ("<" . "<") (">" . ">") ("–" . "-") + ("Ĉ" . "Ĉ") ("ĉ" . "ĉ") ("Ĝ" . "Ĝ") ("ĝ" . "ĝ") + ("Ĥ" . "Ĥ") ("ĥ" . "ĥ") ("Ĵ" . "Ĵ") ("ĵ" . "ĵ") + ("Ŝ" . "Ŝ") ("ŝ" . "ŝ") ("Ŭ" . "Ŭ") ("ŭ" . "ŭ")) + "*Rule that converts character string after the translation." + :type '(repeat + (cons :tag "Rule" + (string :tag "Letter before the converting.") + (string :tag "Letter after the converting."))) + :group 'text-translator) + +(defcustom text-translator-proxy-server + (let ((proxy (or (getenv "HTTP_PROXY") ""))) + (and (string-match "^\\(http://\\)?\\(.+\\):\\([0-9]+\\)" proxy) + (match-string 2 proxy))) + "*Proxy server used." + :type '(choice (string :tag "specify proxy") + (const :tag "not use proxy" nil)) + :group 'text-translator) + +(defcustom text-translator-proxy-port + (let ((proxy (or (getenv "HTTP_PROXY") ""))) + (or (and (string-match "^\\(http://\\)?\\(.+\\):\\([0-9]+\\)" proxy) + (string-to-number (match-string 3 proxy))) + 8080)) + "*Proxy port number used." + :type 'integer + :group 'text-translator) + +(defcustom text-translator-proxy-user nil + "*Basic proxy authorization user name." + :type '(choice (string :tag "Basic proxy authorization user name") + (const :tag "Not use Basic proxy authorization" nil)) + :group 'text-translator) + +(defcustom text-translator-proxy-password nil + "*Basic proxy authorization password." + :type '(choice (string :tag "Basic proxy authorization password") + (const :tag "Not use Basic proxy authorization" nil)) + :group 'text-translator) + +(defcustom text-translator-site-data-template-alist + '(;; Google.com + ("google.com" + "translate.google.com" + "/ HTTP/1.1" + "js=n&prev=_t&hl=ja&ie=UTF-8&text=%s&file=&sl=%o&tl=%t" + utf-8-dos + (lambda () + (text-translator-extract-tag-exclusion-string + "]*>\\(\\(]*>\\([^<]\\|
\\)*
\\)+\\)
")) + (("en" . "ja") ("ja" . "en") + ("en" . "es") ("es" . "en") + ("en" . "fr") ("fr" . "en") + ("en" . "de") ("de" . "en") + ("en" . "it") ("it" . "en") + ("en" . "ar") ("ar" . "en") + ("de" . "fr") ("fr" . "de") + ("en" . "pt") ("pt" . "en") + ("en" . "ru") ("ru" . "en") + ("en" . "ko") ("ko" . "en") + ("en" . "zh-CN") ("zh-CN" . "en") + ("en" . "zh-TW") ("zh-TW" . "en") + ("zh-CN" . "zh-TW") ("zh-TW" . "zh-CN")) + (("zh-TW" . "tw") ("zh-CN" . "ch"))) + + ;; Yahoo.com + ("yahoo.com" + "babelfish.yahoo.com" + "/translate_txt HTTP/1.1" + "ei=UTF-8&doit=done&intl=1&tt=urltext&trtext=%s&lp=%o_%t&btnTrTxt=Translate" + utf-8 + "
\\([^<]*\\)
" + (("en" . "ja") ("ja" . "en") + ("en" . "nl") ("nl" . "en") + ("en" . "fr") ("fr" . "en") + ("en" . "de") ("de" . "en") + ("en" . "el") ("el" . "en") + ("en" . "it") ("it" . "en") + ("en" . "ko") ("ko" . "en") + ("en" . "pt") ("pt" . "en") + ("en" . "ru") ("ru" . "en") + ("en" . "es") ("es" . "en") + ("nl" . "fr") + ("fr" . "de") + ("fr" . "el") ("el" . "fr") + ("fr" . "it") ("it" . "fr") + ("fr" . "pt") ("pt" . "fr") + ("fr" . "es") ("es" . "fr") + ("en" . "zh") ("zh" . "en") + ("en" . "zt") ("zt" . "en")) + (("zh" . "ch") ("zt" . "tw"))) + + ;; Freetranslation.com + ("freetranslation.com" + "ets.freetranslation.com" + "/ HTTP/1.1" + "sequence=core&mode=html&charset=UTF-8&template=results_en-us.htm&language=%o/%t&srctext=%s" + utf-8 + "" + (("English" . "Spanish") ("Spanish" . "English") + ("English" . "French") ("French" . "English") + ("English" . "German") ("German" . "English") + ("English" . "Italian") ("Italian" . "English") + ("English" . "Dutch") ("Dutch" . "English") + ("English" . "Portuguese") ("Portuguese" . "English") + ("English" . "Norwegian")) + (("English" . "en") ("Spanish" . "es") + ("French" . "fr") ("German" . "de") + ("Italian" . "it") ("Dutch" . "nl") + ("Portuguese" . "pt") ("Norwegian" . "no"))) + ("freetranslation.com" + "ets6.freetranslation.com" + "/ HTTP/1.1" + "sequence=core&mode=html&charset=UTF-8&template=results_en-us.htm&language=%o/%t&srctext=%s" + utf-8 + "" + (("English" . "Russian") ("Russian" . "English") + ("English" . "SimplifiedChinese") + ("English" . "TraditionalChinese")) + (("English" . "en") ("Russian" . "ru") + ("SimplifiedChinese" . "ch") ("TraditionalChinese" . "tw"))) + ("freetranslation.com" + "tets9.freetranslation.com" + "/ HTTP/1.1" + "sequence=core&mode=html&charset=UTF-8&template=results_en-us.htm&language=%o/%t&srctext=%s" + utf-8 + "" + (("English" . "Japanese") ("Japanese" . "English")) + (("English" . "en") ("Japanese" . "ja"))) + + ;; Livedoor.com + ("livedoor.com" + "translate.livedoor.com" + "/ HTTP/1.1" + "clear_flg=1&src_text=%s&trns_type=%o,%t&sumit=翻訳" + utf-8 + "" + (("1" . "2") ("2" . "1") + ("2" . "9") ("9" . "2") + ("2" . "6") ("6" . "2")) + (("1" . "en") ("2" . "ja") + ("6" . "ch") ("9" . "ko"))) + + ;; Fresheye.com + ("fresheye.com" + "mt.fresheye.com" + "/ft_result.cgi HTTP/1.1" + "gen_text=%s&e=%o%t" + utf-8 + "" + (("E" . "J") ("J" . "E")) + (("E" . "en") ("J" . "ja"))) + ("fresheye.com" + "mt.fresheye.com" + "/ft_cjresult.cgi HTTP/1.1" + "gen_text=%s&charset=gb2312&cjjc=%o%t" + utf-8 + "" + (("c" . "j") ("j" . "c") ("e" . "c")) + (("c" . "ch") ("j" . "ja") ("e" . "en"))) + ("fresheye.com" + "mt.fresheye.com" + "/ft_cjresult.cgi HTTP/1.1" + "gen_text=%s&charset=big5&cjjc=%o%t" + utf-8 + "" + (("c" . "j") ("j" . "c") ("e" . "c")) + (("c" . "tw") ("j" . "ja") ("e" . "en"))) + + ;; Excite.co.jp + ("excite.co.jp" + "www.excite.co.jp" + "/world/english/ HTTP/1.1" + "wb_lp=%o%t&before=%s" + utf-8 + "" + (("EN" . "JA") ("JA" . "EN")) + (("EN" . "en") ("JA" . "ja"))) + ("excite.co.jp" + "www.excite.co.jp" + "/world/chinese/ HTTP/1.1" + "wb_lp=%o%t&before=%s" + utf-8 + "" + (("JA" . "CH") ("CH" . "JA")) + (("JA" . "ja") ("CH" . "ch"))) + ("excite.co.jp" + "www.excite.co.jp" + "/world/chinese/ HTTP/1.1" + "wb_lp=%o%t&big5=yes&before=%s" + utf-8 + "" + (("JA" . "CH") ("CH" . "JA")) + (("JA" . "ja") ("CH" . "tw"))) + ("excite.co.jp" + "www.excite.co.jp" + "/world/korean/ HTTP/1.1" + "wb_lp=%o%t&before=%s" + utf-8 + "" + (("JA" . "KO") ("KO" . "JA")) + (("JA" . "ja") ("KO" . "ko"))) + + ;; Yahoo.co.jp + ("yahoo.co.jp" + "honyaku.yahoo.co.jp" + "/transtext HTTP/1.1" + "both=TH&text=%s&clearFlg=1&eid=CR-%o%t" + utf-8 + "" + (("E" . "J") ("J" . "E") + ("C" . "J") ("J" . "C-CN") + ("K" . "J") ("J" . "K")) + (("E" . "en") ("J" . "ja") + ("C" . "ch") ("C-CN" . "ch") + ("K" . "ko"))) + + ;; Ocn.ne.jp + ("ocn.ne.jp" + "cgi01.ocn.ne.jp" + "/cgi-bin/translation/index.cgi HTTP/1.1" + "langpair=%o%t&sourceText=%s" + utf-8 + "" + (("en" . "ja") ("ja" . "en") + ("ja" . "ko") ("ko" . "ja") + ("ja" . "zh") ("zh" . "ja")) + (("zh" . "ch")))) + "The alist where setting of the site which is used for text translation is +described. To update site-data, evalute `text-translator-site-data-init`." + :type '(repeat + (list :tag "Web Site" + (string :tag "Web site name and translation type") + (string :tag "Host name") + (string :tag "POST path and HTTP version") + (string :tag "POST contents") + (symbol :tag "Character code") + (choice (string :tag "regexp") (symbol :tag "function")) + (list :tag (concat "The correspondence of translation-able " + "name (used by translation sites)")) + (list :tag (concat "The correspondence of name that used by " + "text-translator and name that used by " + "translation sites")))) + :group 'text-translator) + +(defcustom text-translator-site-data-minimum-alist + '(;; lou5.jp (Japanese, Lou) + ("lou5.jp_*normal" + "lou5.jp" + "/ HTTP/1.1" + "v=1&text=%s" + utf-8 + (lambda () + (text-translator-extract-tag-exclusion-string + "

\\(\\(.\\|\n\\)*?\\)

" + t))) + ;; lou5.jp (Japanese, Lou Blog) + ("lou5.jp_*blog" + "lou5.jp" + "/ HTTP/1.1" + "v=2&text=%s" + utf-8 + "

\\(\\(.\\|\n\\)*?\\)

") + + ;; tatoeba.org (Furigana, romaji) + ("tatoeba.org_furigana" + "tatoeba.org" + "/eng/tools/romaji_furigana?query=%s&type=furigana HTTP/1.1" + nil + utf-8 + "class=\"furigana\">\\(\\(.\\|\n\\)*?\\)
\\(\\(.\\|\n\\)*?\\)\\(\\(.\\|\n\\)*?\\)") + ("traduku.net_eneo" + "traduku.net" + "/cgi-bin/traduku HTTP/1.0" + "en_eo_trukilo&t=%s" + utf-8 + " id=\"rezulto\">\\(\\(.\\|\n\\)*?\\)")) + + "*The alist where setting of the site which is used for text translation is +described. To update site-data, evalute `text-translator-site-data-init`." + :type '(repeat + (list :tag "Web Site" + (string :tag "Web site name and translation type") + (string :tag "Host name") + (string :tag "POST path and HTTP version") + (string :tag "POST contents") + (symbol :tag "Character code") + (choice (string :tag "regexp") (symbol :tag "function")))) + :group 'text-translator) + +;; text-translator-site-data-template-alist +;; + text-translator-site-data-minimum-alist +;; = text-translator-site-data-alist +(defvar text-translator-site-data-alist nil + "The alist where setting of the site which is used for text translation is +described.") + +(defcustom text-translator-default-engine "google.com_enja" + "*Translation engine used by default." + :type (cons 'radio + (mapcar + (lambda (x) + (list 'const (car x))) + text-translator-site-data-alist)) + :group 'text-translator) + +(defcustom text-translator-user-agent +;; "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4" + "Mozilla/5.0 (Windows; U; Windows NT 5.0; ja; rv:1.9) Gecko/2008052906 Firefox/3.0" + "*text-translator's User Agent. Default is Firefox." + :type 'string + :group 'text-translator) + +(defcustom text-translator-mode-hook nil + "*Hook run at the end of function `text-translator-mode'." + :type 'hook + :group 'text-translator) + +(defcustom text-translator-auto-selection-func nil + "*Value is function that select translation engine automatic. +this value is function for `text-translator-translate-by-auto-selection'." + :type 'symbol + :group 'text-translator) + +(defcustom text-translator-display-popup nil + "*Non-nil means translated message is displayed by using popup-tip. +To use this option, you have to require popup.el. +popup.el URL: http://github.com/m2ym/auto-complete" + :type 'symbol + :group 'text-translator) + +(defcustom text-translator-do-fill-region nil + "*Default is nil. if value is non-nil, it deletes +linefeed\\(and CR\\) from pre translation string(\"\\n\" -> \" \", +\"\r\" -> \"\"). and processing to straighten faces with +fill-paragraph after the translation. it is countermeasure +against the translation engines that processes per line." + :type 'symbol + :group 'text-translator) + +(defcustom text-translator-space-division-languages + '("en" "es" "fr" "de" "it" "pt" "ru" "nl" "el" "no") + "*List of language that word is delimited by blank." + :type '(repeat (string :tag "language(2char)")) + :group 'text-translator) + +(defvar text-translator-last-string "" + "The last time, character string which was thrown to the translation site.") + +(defvar text-translator-engine-history nil + "The history of translation engine which you used.") + +(defvar text-translator-search-regexp-or-func nil) + +(defvar text-translator-sitedata-hash nil) + +(provide 'text-translator-vars) +;;; text-translator-vars.el ends here + +;; Local Variables: +;; Coding: utf-8 +;; End: diff -r c57c251fb82b -r 7935aa4dacbe emacs-pkg-text-translator/stuff/text-translator.el --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emacs-pkg-text-translator/stuff/text-translator.el Sun Feb 06 22:20:54 2011 +0100 @@ -0,0 +1,555 @@ +;;; text-translator.el --- Text Translator + +;; Copyright (C) 2007-2010 khiker + +;; Author: khiker +;; plus + +;; This file is free software; you can redistribute it and/or modify +;; it under the terms of the GNU General Public License as published by +;; the Free Software Foundation; either version 2, or (at your option) +;; any later version. + +;; This file is distributed in the hope that it will be useful, +;; but WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;; GNU General Public License for more details. + +;; You should have received a copy of the GNU General Public License +;; along with GNU Emacs; see the file COPYING. If not, write to +;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +;; Boston, MA 02110-1301, USA. + +;;; Commentary: + +;; Translates character strings on Emacs. +;; This package use the text translation service that exists on the internet. + +;; Read README.en (English) or README.ja (Japanese). + +;;; Code: + +(require 'text-translator-vars) + +(defun text-translator (arg &optional last engine-or-func) + "The function which does text translation. +Use Excite, Google and so translation site. +1. Mark is active + - Prefix was supplied. + 1. Choose translation site which you use. + 2. Translate by type which you selected. + - Prefix was not supplied. + Translate range of region that you selected by + first element of `text-translator-engine-history'. + (If `text-translator-engine-history' is nil, + use `text-translator-default-engine'.) +2. Mark is deactive + - Prefix was supplied. + 1. Choose translation site which you use. + 2. Translate value which you input from minibuffer by type you selected. + - Prefix was not supplied. + Translate value which you input from minibuffer by + first element of `text-translator-engine-history'. + (If `text-translator-engine-history' is nil, + use `text-translator-default-engine'.)" + (interactive "P") + (add-to-list 'text-translator-engine-history text-translator-default-engine) + (let ((minibuffer-history text-translator-engine-history) + (engine (text-translator-check-valid-translation-engine + engine-or-func (car text-translator-engine-history))) + str) + ;; If prefix-arg is non-nil, change translation type. + (when (or arg last) + (setq engine (completing-read + (format "Select translation engine (default %s): " engine) + text-translator-site-data-alist nil t nil nil engine))) + (setq str + (cond + (last + text-translator-last-string) + (t + (text-translator-region-or-read-string + (format "Enter string translated by %s: " engine))))) + (text-translator-client + (text-translator-check-valid-translation-engine + (and (functionp engine-or-func) (funcall engine-or-func engine str)) + engine) + str))) + +(defun text-translator-translate-by-auto-selection (arg) + "Function that translates by auto selection of translation engine. +Function that select automatically is value of `text-translator-auto-selection-func'." + (interactive "P") + (text-translator arg nil text-translator-auto-selection-func)) + +(defun text-translator-translate-by-auto-selection-enja (engine str) + "Automatic selection function for English to Japanese(or Japanese to English) +translation. +If alphabet ratio is over 40%, select engine which is translating from English to Japanese. +Otherwise, from Japanese to English." + (setq str (or str "")) + (format + "%s_%s" + (text-translator-get-engine-type-or-site engine t) + (if (> (/ (* (length (replace-regexp-in-string "[^A-Za-z]+" "" str)) 100) + (length str)) + 40) + "enja" "jaen"))) + +(defun text-translator-translate-last-string () + "The function to translate in the translation site that +I choose with the character string that I translated in the last time." + (interactive) + (text-translator nil t)) + + +(defun text-translator-region-or-read-string (&optional prompt) + "If mark is active, return the region, otherwise, read string with PROMPT." + (cond + (mark-active + (buffer-substring-no-properties (region-beginning) (region-end))) + (t + (read-string (or prompt "Enter string: "))))) + +(defun text-translator-all (arg &optional key str) + "The function to translate in all of translate sites that matches +the selected type." + (interactive "P") + (let ((hash text-translator-sitedata-hash) + keys) + (setq str (or str (text-translator-region-or-read-string))) + (when (or (null hash) + arg) + (setq text-translator-sitedata-hash + (text-translator-update-hashtable)) + (setq hash text-translator-sitedata-hash)) + (maphash '(lambda (x y) + (setq keys (cons x keys))) + hash) + (setq key (or key (completing-read "Select type: " keys nil t))) + (when key + (save-selected-window + (pop-to-buffer text-translator-buffer) + (setq buffer-read-only nil) + (erase-buffer) + (text-translator-mode)) + (let ((sites (gethash key hash))) + (setq text-translator-last-string str) + (setq text-translator-search-regexp-or-func + (concat "_" key)) + (dolist (i sites) + (text-translator-client i str t)))))) + +(defun text-translator-all-by-auto-selection (arg) + "The function to translate in all of translate sites, whose translation engine is selected automatically. +The selection function is the value of `text-translator-auto-selection-func'." + (interactive "P") + (let ((str (text-translator-region-or-read-string))) + (text-translator-all + arg + (substring (funcall text-translator-auto-selection-func "" str) 1) + str))) + +(defun text-translator-client (engine str &optional all) + "Function that throws out words and phrases that want to translate into +specified site, and receives translation result." + (let* ((history-delete-duplicates t) + (buf (cond (all + (concat text-translator-work-buffer + (replace-regexp-in-string "_.*" + "" + engine))) + (t + text-translator-work-buffer))) + (alist + (cond + ((not text-translator-do-fill-region) + text-translator-pre-string-replace-alist) + ;; for example, if engine is "excite.co.jp_enja", + ;; this code returns "en". + ((member (substring + (text-translator-get-engine-type-or-site engine) 0 2) + text-translator-space-division-languages) + ;; replace "\n" to " ". + (append '(("\n" . " ") ("\r" . "")) + text-translator-pre-string-replace-alist)) + (t + ;; replace "\n" to "". + (append '(("\n" . "") ("\r" . "")) + text-translator-pre-string-replace-alist)))) + (str (text-translator-replace-string str alist)) + (type (assoc engine text-translator-site-data-alist)) + (proc (open-network-stream "Web Connection" buf + (or text-translator-proxy-server + (nth 1 type)) + (or (and text-translator-proxy-server + text-translator-proxy-port) + 80))) + ;;(process-connection-type nil) + (enc-str (text-translator-url-encode-string str (nth 4 type))) + (post-str (if (nth 3 type) (format (nth 3 type) enc-str) nil)) + (truncate-partial-width-windows nil)) + (unless all + (add-to-history 'text-translator-engine-history engine) + (setq text-translator-search-regexp-or-func (nth 5 type)) + (setq text-translator-last-string str)) + (with-current-buffer (get-buffer-create buf) + (erase-buffer) + (set-process-coding-system proc (nth 4 type) 'binary) + (set-process-filter proc 'text-translator-client-filter) + (process-send-string + proc + (concat + (cond + (post-str + ;; use POST method + (concat "POST " (nth 2 type) "\r\n")) + (t + ;; use GET method + (concat "GET " (format (nth 2 type) enc-str) "\r\n"))) + (and text-translator-proxy-server + text-translator-proxy-user + text-translator-proxy-password + (format "Proxy-Authorization: Basic %s \r\n" + (base64-encode-string + (concat text-translator-proxy-user ":" + text-translator-proxy-password)))) + "HOST: " (nth 1 type) "\r\n" + "User-Agent: " text-translator-user-agent "\r\n" +;; "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" +;; "Accept-Language: ja,en-us;q=0.7,en;q=0.3" "\r\n" + "Accept-Encoding: identity\r\n" + "Accept-Charset: Shift_JIS,utf-8;q=0.7,*;q=0.7\r\n" + "Keep-Alive: 300" "\r\n" + "Connection: keep-alive" "\r\n" + (when post-str + (concat + "Content-Type: application/x-www-form-urlencoded\r\n" + "Content-Length: " + (number-to-string (string-bytes post-str)) "\r\n" + "\r\n" + post-str "\r\n")) + "\r\n")) + (message "Translating...") + (unless (or all + text-translator-display-popup) + (save-selected-window + (pop-to-buffer text-translator-buffer) + (setq buffer-read-only nil) + (erase-buffer) + (text-translator-mode) + (setq mode-line-buffer-identification + `("%b [" ,(car text-translator-engine-history) "]"))))))) + +(defun text-translator-client-filter (proc str) + (let ((regex-or-func text-translator-search-regexp-or-func) + bname all-flag) + (with-current-buffer (process-buffer proc) + (goto-char (process-mark proc)) + (insert (format "%s" str)) + (set-marker (process-mark proc) (point)) + (setq bname (buffer-name)) + (setq all-flag (not (string= bname text-translator-work-buffer))) + (when all-flag + (setq regex-or-func + (nth 5 + (assoc (concat + (substring bname + (length text-translator-work-buffer) + (length bname)) + regex-or-func) + text-translator-site-data-alist)))) + (setq str (text-translator-replace-string + (or (cond + ((functionp regex-or-func) + (funcall regex-or-func)) + ((re-search-backward regex-or-func nil t) + (match-string 1))) + "") + text-translator-post-string-replace-alist)) + (unless (string= "" str) + (delete-process proc) + (setq bname (buffer-name)) + (setq all-flag (not (string= bname text-translator-work-buffer))) + (when (or all-flag + (not text-translator-display-popup)) + (text-translator-display-window str bname all-flag)))) + ;; To display in popup-tip, buffer is out of with-current-buffer. + (when (and (not (string= "" str)) + (not all-flag) + (fboundp 'popup-tip) + (eq text-translator-display-popup t)) + (text-translator-display-popup str)))) + +(defun text-translator-display-window (str buf all-flag) + (let ((window (get-buffer-window text-translator-buffer)) + (window-min-height + (if (> text-translator-window-min-height (/ (frame-height) 2)) + (/ (frame-height) 2) + (1+ text-translator-window-min-height)))) + (set-buffer text-translator-buffer) + (setq buffer-read-only nil) + (cond + (all-flag + (insert (concat + (propertize + (format "----- %s -----\n" + (substring buf + (length text-translator-work-buffer) + (length buf))) + 'face font-lock-keyword-face) + str "\n\n"))) + (t (when text-translator-leave-string + (insert + (concat + (propertize "----- Original -----\n" + 'face font-lock-keyword-face) + text-translator-last-string + "\n\n" + (propertize "***** Translation *****\n" + 'face font-lock-keyword-face)))) + (insert (concat str "\n")) + (when text-translator-do-fill-region + (goto-char (- (point) (/ (length str) 2))) + (call-interactively 'fill-paragraph)) + (set-buffer-modified-p nil) + ;; adjust window height + (when (and text-translator-auto-window-adjust + (window-live-p window)) + (balance-windows) + (shrink-window-if-larger-than-buffer window)) + (message "") ; prevent minibuffer from becoming two line. + (ding) + (message "Translating...done"))))) + +(defun text-translator-display-popup (str) + (let ((read-only-p buffer-read-only)) + (setq str (with-temp-buffer + (insert str) + (when text-translator-do-fill-region + (goto-char (- (point) (/ (length str) 2))) + (call-interactively 'fill-paragraph)) + (buffer-string))) + (ding) + (message "Translating...done") + (if read-only-p + ;; temporay cancel buffer-read-only + (unwind-protect (progn + (setq buffer-read-only nil) + (popup-tip str :margin t)) + (setq buffer-read-only t)) + (popup-tip str :margin t)))) + +(defun text-translator-update-hashtable () + (let ((hash (make-hash-table :test 'equal))) + (mapc '(lambda (x) + (let ((matched (replace-regexp-in-string "\\([^_]*\\)_" + "" + (car x)))) + (unless (or (string= (car x) matched) + (eq ?* (aref matched 0))) + (cond + ((gethash matched hash) + (puthash matched + (cons (car x) (gethash matched hash)) + hash)) + (t + (puthash matched (list (car x)) hash)))))) + text-translator-site-data-alist) + hash)) + +(defun text-translator-replace-string (str replace) + "Function that converts character string specified for argument STR +according to rule REPLACE." + (with-temp-buffer + (insert str) + ;; convert unusable string + (format-replace-strings replace) + (buffer-string))) + +(defun text-translator-extract-tag-exclusion-string (regex &optional dont-convert-br) +;; (when (re-search-backward regex nil t) + (when (re-search-backward regex nil t) + ;; first: convert
tag to '\n' (when variable dont-convert-br is nil) + ;; second: convert any another tags to empty string. + (let ((matchstr (match-string 1))) + (setq matchstr + (text-translator-replace-string + matchstr + text-translator-post-string-replace-alist)) + (replace-regexp-in-string + "<.*?>" "" (if dont-convert-br + matchstr + (replace-regexp-in-string + "<[bB][rR]\\( /\\)?>" "\n" matchstr)))))) + +;;;; major-mode text-translator-mode + +;; variables for major mode +(defvar text-translator-mode nil) +(defvar text-translator-mode-map nil) +(defvar text-translator-mode-pkey-map nil) +(defvar text-translator-mode-syntax-table nil) +(defvar text-translator-mode-abbrev-table nil) +(define-abbrev-table 'text-translator-mode-abbrev-table ()) + +;; keymap definition +(unless text-translator-mode-map + (setq text-translator-mode-map (make-sparse-keymap)) + (define-prefix-command 'text-translator-mode-pkey-map) + (let ((map text-translator-mode-pkey-map)) + (define-key map "\C-q" 'text-translator-quit) + (define-key map "\C-a" 'text-translator-translate-recent-type) + (define-key map "\C-l" 'text-translator-display-last-string) + (define-key map "\C-d" 'text-translator-translate-default) + (define-key map "\C-s" 'text-translator-toggle-leave-string))) + +;; major-mode +(defun text-translator-mode () + "Major mode for text-translator." + (kill-all-local-variables) + (setq local-abbrev-table text-translator-mode-abbrev-table) + (set-syntax-table text-translator-mode-syntax-table) + (setq mode-name text-translator-mode-name) + (setq major-mode 'text-translator-mode) + (define-key text-translator-mode-map + text-translator-prefix-key text-translator-mode-pkey-map) + (use-local-map text-translator-mode-map) + (run-hooks 'text-translator-mode-hook)) + +;; syntax-table +(unless text-translator-mode-syntax-table + (setq text-translator-mode-syntax-table (make-syntax-table))) + +;; functions for major-mode +(defun text-translator-quit () + "Function that closes buffer for text-translator. +If window only have *translated* buffer, change another buffer." + (interactive) + (bury-buffer) + (unless (one-window-p) + (delete-window))) + +(defun text-translator-toggle-leave-string () + "Function that change value of `text-translator-leave-string'. +Toggle to display a translation result buffer of character +string that used last time." + (interactive) + (setq text-translator-leave-string (not text-translator-leave-string)) + (message "Pretranslational string switched %s to leave." + (if text-translator-leave-string "" " not"))) + +(defun text-translator-display-last-string (arg) + "Function that displays translated character string last time. +Default display to minibuffer. +With prefix-arg, insert buffer." + (interactive "P") + (if arg + (insert text-translator-last-string) + (message "%s" text-translator-last-string))) + +(defun text-translator-translate-recent-type () + "Function that translates by type corresponding to the language +that used last time. +For example, last time, if you have used excite.co.jp_enja, +this time select from **_enja, and, translates." + (interactive) + (let* ((minibuffer-history text-translator-engine-history) + (engine (car text-translator-engine-history)) + (last-type + (concat "_" (text-translator-get-engine-type-or-site engine))) + (type (completing-read + (format "Select translation engine (last %s): " engine) + (delq nil + (mapcar + (lambda (x) + (when (string-match last-type (car x)) + x)) + text-translator-site-data-alist)) + nil t))) + (unless (string= "" type) + (text-translator-client type text-translator-last-string)))) + +(defun text-translator-translate-default () + "Function that translates by default type only. +Default is value of `text-translator-default-engine'." + (interactive) + (text-translator nil nil text-translator-default-engine)) + +(defun text-translator-check-valid-translation-engine (engine valid-engine) + "Check ENGINE that is registered in `text-translator-site-data-alist'. +Return ENGINE if it is already registered, otherwise return VALID-ENGINE." + (or (car (member engine (mapcar 'car text-translator-site-data-alist))) + valid-engine)) + +(defun text-translator-get-engine-type-or-site (engine &optional get-site) + "Get a translation engine type or site name. +If optional argument GET-SITE is nil, return a translation engine type. +Otherwise return a translation site name." + (nth (if get-site 0 1) (split-string engine "_"))) + +;; by google2.el +(defun text-translator-url-encode-string (str &optional coding) + (apply (function concat) + (mapcar + (lambda (ch) + (cond + ((eq ch ?\n) ; newline + "%0D%0A") + ((string-match "[-a-zA-Z0-9_:/]" (char-to-string ch)) ; xxx? + (char-to-string ch)) ; printable + ((char-equal ch ?\x20) ; space + "+") + (t + (format "%%%02X" ch)))) ; escape + ;; Coerce a string to a list of chars. + (append (encode-coding-string (or str "") (or coding 'iso-2022-jp)) + nil)))) + +;; initialization function +(defun text-translator-site-data-init () + ;; initialize + (setq text-translator-site-data-alist nil) + (setq text-translator-site-data-alist + text-translator-site-data-minimum-alist) + (dolist (site text-translator-site-data-template-alist) + (let ((tt-convert-name '(lambda (lang) + (let ((match-lang (assoc lang + (nth 7 site)))) + (if match-lang + (cdr match-lang) + lang)))) + (tt-replace-string '(lambda (pstr olang tlang) + (when olang + (setq pstr + (replace-regexp-in-string "%o" + olang + pstr))) + (when tlang + (setq pstr + (replace-regexp-in-string "%t" + tlang + pstr)) + pstr))) + tt-alist) + (dolist (i (nth 6 site)) + (add-to-list 'text-translator-site-data-alist + (list (format "%s" + (concat (nth 0 site) + "_" + (funcall tt-convert-name (car i)) + (funcall tt-convert-name (cdr i)))) + (nth 1 site) + (nth 2 site) + (funcall tt-replace-string + (nth 3 site) (car i) (cdr i)) + (nth 4 site) + (nth 5 site))))))) +(text-translator-site-data-init) ; init + +(provide 'text-translator) +;;; text-translator.el ends here + +;; Local Variables: +;; Coding: utf-8 +;; End: diff -r c57c251fb82b -r 7935aa4dacbe emacs-pkg-vala-mode/stuff/80-vala-init.el --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/emacs-pkg-vala-mode/stuff/80-vala-init.el Sun Feb 06 22:20:54 2011 +0100 @@ -0,0 +1,5 @@ +;; Register vala-mode + +(autoload 'vala-mode "vala-mode" "Major mode for editing Vala code." t) +(add-to-list 'auto-mode-alist '("\\.vala$" . vala-mode)) +(add-to-list 'auto-mode-alist '("\\.vapi$" . vala-mode))