Update
[elisp/gnus.git-] / lisp / gnus-i18n.el
1 ;;; gnus-i18n.el --- Internationalization for Gnus
2
3 ;; Copyright (C) 1996,1997 Free Software Foundation, Inc.
4
5 ;; Author: MORIOKA Tomohiko <morioka@jaist.ac.jp>
6 ;; Created: 1997/11/27
7 ;; Keywords: internationalization, news, mail
8
9 ;; This file is not part of GNU Emacs yet.
10
11 ;; This program is free software; you can redistribute it and/or
12 ;; modify it under the terms of the GNU General Public License as
13 ;; published by the Free Software Foundation; either version 2, or (at
14 ;; your option) any later version.
15
16 ;; This program is distributed in the hope that it will be useful, but
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19 ;; General Public License for more details.
20
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
25
26 ;;; Code:
27
28 (require 'gnus-sum)
29 (require 'gnus-util)
30
31 ;;; @ newsgroup default charset
32 ;;;
33
34 (defvar gnus-newsgroup-default-charset-alist
35   '(("^\\(fj\\|tnn\\|japan\\)\\."       . iso-2022-jp-2)
36     ("^han\\."                          . euc-kr)
37     ("^relcom\\."                       . koi8-r)
38     ("^alt\\.chinese\\.text\\.big5"     . cn-big5)
39     ("^hk\\(star\\)?\\."                . cn-big5)
40     ("^tw\\."                           . cn-big5)
41     ("^alt\\.chinese"                   . hz-gb-2312)
42     )
43   "Alist of newsgroup patterns vs. corresponding default MIME charset.
44 Each element looks like (REGEXP . SYMBOL).  REGEXP is pattern for
45 newsgroup name.  SYMBOL is MIME charset or coding-system.")
46
47 (defun gnus-set-newsgroup-default-charset (newsgroup charset)
48   "Set CHARSET for the NEWSGROUP as default MIME charset."
49   (let* ((ng-regexp (concat "^" (regexp-quote newsgroup) "\\($\\|\\.\\)"))
50          (pair (assoc ng-regexp gnus-newsgroup-default-charset-alist)))
51     (if pair
52         (setcdr pair charset)
53       (setq gnus-newsgroup-default-charset-alist
54             (cons (cons ng-regexp charset)
55                   gnus-newsgroup-default-charset-alist)))))
56
57
58 ;;; @ localization
59 ;;;
60
61 (defun gnus-set-summary-default-charset ()
62   "Set up `default-mime-charset' of summary buffer.
63 It is specified by variable `gnus-newsgroup-default-charset-alist'
64 \(cf. function `gnus-set-newsgroup-default-charset')."
65   (if (buffer-live-p gnus-summary-buffer)
66       (let* ((qgroup (save-excursion
67                        (set-buffer gnus-summary-buffer)
68                        gnus-newsgroup-name))
69              (rgroup (gnus-group-real-name qgroup))
70              alist pair charset)
71         (setq charset (catch 'found
72                         ;; First, use "qualified" newsgroup name.
73                         (setq alist gnus-newsgroup-default-charset-alist)
74                         (while (setq pair (car alist))
75                           (if (string-match (car pair) qgroup)
76                               (throw 'found (cdr pair)))
77                           (setq alist (cdr alist)))
78                         ;; Next, try "real" newsgroup name.
79                         (setq alist gnus-newsgroup-default-charset-alist)
80                         (while (setq pair (car alist))
81                           (if (string-match (car pair) rgroup)
82                               (throw 'found (cdr pair)))
83                           (setq alist (cdr alist)))))
84         (if charset
85             (progn
86               (save-excursion
87                 (set-buffer gnus-summary-buffer)
88                 (make-local-variable 'default-mime-charset)
89                 (setq default-mime-charset charset))
90               (make-local-variable 'default-mime-charset)
91               (setq default-mime-charset charset))
92           (kill-local-variable 'default-mime-charset)))))
93
94
95 ;;; @ end
96 ;;;
97
98 (provide 'gnus-i18n)
99
100 ;;; gnus-i18n.el ends here