6a1a1fd2ebd5c4254c3cd25cb20b1fd342a28423
[chise/tomoyo-tools.git] / ideo-trans.el
1 ;;; ideo-trans.el --- Translation utility for Ideographic Strings
2
3 ;; Copyright (C) 2003,2004 MORIOKA Tomohiko
4
5 ;; Author: MORIOKA Tomohiko <tomo@kanji.zinbun.kyoto-u.ac.jp>
6 ;; Keywords: Ideographs, Character Database, Chaon, CHISE
7
8 ;; This file is a part of tomoyo-tools.
9
10 ;; This program is free software; you can redistribute it and/or
11 ;; modify it under the terms of the GNU General Public License as
12 ;; published by the Free Software Foundation; either version 2, or (at
13 ;; your option) any later version.
14
15 ;; This program is distributed in the hope that it will be useful, but
16 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 ;; General Public License for more details.
19
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with this program; see the file COPYING.  If not, write to
22 ;; the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 ;; Boston, MA 02111-1307, USA.
24
25 ;;; Code:
26
27 ;;;###autoload
28 (defun ideo-translate-string-into-simplified-chinese (string)
29   "Simplify Chinese traditional characters in STRING."
30   (let (uchr ret)
31     (mapconcat
32      (lambda (chr)
33        (setq uchr
34              (if (setq ret (or (char-ucs chr)
35                                (get-char-attribute chr '=>ucs@gb)))
36                  (decode-char '=ucs ret)
37                chr))
38        (char-to-string
39         (if (setq ret (encode-char uchr 'chinese-gb12345))
40             (decode-char 'chinese-gb2312 ret)
41           chr)))
42      string "")))
43
44 ;;;###autoload
45 (define-obsolete-function-alias 'ideo-trans-simplify-chinese-string
46   'ideo-translate-string-into-simplified-chinese)
47
48 ;;;###autoload
49 (defun ideo-translate-region-into-traditional (start end)
50   (interactive "r")
51   (save-excursion
52     (save-restriction
53       (narrow-to-region start end)
54       (goto-char start)
55       (let (chr ret rret i prompt)
56         (while (and (skip-chars-forward "\x00-\xFF")
57                     (not (eobp)))
58           (setq chr (char-after))
59           (if (setq ret (or (get-char-attribute chr '<-simplified@JP/Jouyou)
60                             (get-char-attribute chr '<-simplified@jp-jouyou)
61                             (get-char-attribute chr '<-simplified@JP)
62                             (get-char-attribute chr '<-simplified@jp)
63                             (get-char-attribute chr '<-jp-simplified)
64                             (get-char-attribute chr '<-simplified)))
65               (progn
66                 (if (cdr ret)
67                     (progn
68                       (setq i 0)
69                       (setq prompt
70                             (concat
71                              (mapconcat (lambda (cell)
72                                           (setq i (1+ i))
73                                           (format "%d. %c" i cell))
74                                         ret " ")
75                              " : "))
76                       (while (and (setq rret
77                                         (string-to-int
78                                          (read-string prompt)))
79                                   (not (and (< 0 rret)
80                                             (<=  rret (length ret))))))
81                       (delete-char)
82                       (insert (nth (1- rret) ret)))
83                   (delete-char)
84                   (insert (car ret))))
85             (or (eobp)
86                 (forward-char))))))))
87
88
89 ;;; @ End.
90 ;;;
91
92 (provide 'ideo-trans)
93
94 ;;; ideo-trans.el ends here