1 ;;; riece-mcat.el --- message catalog
2 ;; Copyright (C) 2007 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
6 ;; This file is part of Riece.
8 ;; This program is free software; you can redistribute it and/or modify
9 ;; it under the terms of the GNU General Public License as published by
10 ;; the Free Software Foundation; either version 2, or (at your option)
13 ;; This program is distributed in the hope that it will be useful,
14 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 ;; GNU General Public License for more details.
18 ;; You should have received a copy of the GNU General Public License
19 ;; along with GNU Emacs; see the file COPYING. If not, write to the
20 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 ;; Boston, MA 02110-1301, USA.
27 (defun riece-mcat (string)
28 "Translate STRING in the current language environment."
29 (let ((feature (if (featurep 'mule)
30 (get-language-info current-language-environment
31 'riece-mcat-feature))))
35 (or (cdr (assoc string
37 (intern (concat (symbol-name feature) "-alist")))))
41 (defun riece-mcat-extract-from-form (form)
42 (if (and form (listp form) (listp (cdr form)))
43 (if (eq (car form) 'riece-mcat)
45 (delq nil (apply #'nconc
46 (mapcar #'riece-mcat-extract-from-form form))))))
48 (defun riece-mcat-extract (files)
50 (let (message-list pointer)
53 (insert-file-contents (car files))
54 (goto-char (point-min))
56 (while (progn (skip-chars-forward " \t\n\f")
62 (riece-mcat-extract-from-form
63 (read (current-buffer)))))))
64 (setq files (cdr files)))
65 (setq message-list (sort message-list #'string-lessp)
68 (if (member (car pointer) (cdr pointer))
70 (setq pointer (cdr pointer)))
71 (delq nil message-list))))
73 (defun riece-mcat-update (files mcat-file mcat-alist-symbol)
75 (let ((pp-escape-newlines t)
78 (set-buffer (find-file-noselect mcat-file))
79 (goto-char (point-min))
80 (if (re-search-forward (concat "^\\s-*(\\(defvar\\|defconst\\)\\s-+"
81 (regexp-quote (symbol-name
85 (goto-char (match-beginning 0))
87 (eval (read (current-buffer))))
88 (delete-region (point) (progn (forward-sexp) (point))))
89 (set mcat-alist-symbol nil))
90 (setq alist (mapcar (lambda (message)
92 (symbol-value mcat-alist-symbol))
94 (riece-mcat-extract files)))
95 (insert "(defconst " (symbol-name mcat-alist-symbol) "\n '(")
97 (insert "(" (pp-to-string (car (car alist))) " . "
98 (pp-to-string (cdr (car alist))) ")")
101 (setq alist (cdr alist)))
105 (defconst riece-mcat-description "Translate messages")
107 (defun riece-mcat-insinuate ()
108 (set-language-info "Japanese" 'riece-mcat-feature 'riece-mcat-japanese))
110 (defun riece-mcat-uninstall ()
111 (set-language-info "Japanese" 'riece-mcat-feature nil))
113 (provide 'riece-mcat)
115 ;;; riece-mcat.el ends here