9d1a0ae4f47f638ef9257dcc220687d02d1e3515
[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 ;;; @ newsgroup default charset
29 ;;;
30
31 (defvar gnus-newsgroup-default-charset-alist
32   '(("\\(^\\|:\\)\\(fj\\|tnn\\|japan\\)\\."     . iso-2022-jp-2)
33     ("\\(^\\|:\\)han\\."                        . euc-kr)
34     ("\\(^\\|:\\)relcom\\."                     . koi8-r)
35     ("\\(^\\|:\\)alt\\.chinese\\.text\\.big5"   . cn-big5)
36     ("\\(^\\|:\\)hk\\(star\\)?\\."              . cn-big5)
37     ("\\(^\\|:\\)tw\\."                         . cn-big5)
38     ("\\(^\\|:\\)alt\\.chinese"                 . hz-gb-2312)
39     ("\\`nndraft:\\(drafts\\|delayed\\)\\'"     . nil)
40     )
41   "Alist of newsgroup patterns vs. corresponding default MIME charset.
42 Each element looks like (REGEXP . SYMBOL).  REGEXP is pattern for
43 newsgroup name.  SYMBOL is MIME charset or coding-system.")
44
45 (defun gnus-set-newsgroup-default-charset (newsgroup charset)
46   "Set CHARSET for the NEWSGROUP as default MIME charset."
47   (let* ((ng-regexp (concat "^" (regexp-quote newsgroup) "\\($\\|\\.\\)"))
48          (pair (assoc ng-regexp gnus-newsgroup-default-charset-alist))
49          )
50     (if pair
51         (setcdr pair charset)
52       (setq gnus-newsgroup-default-charset-alist
53             (cons (cons ng-regexp charset)
54                   gnus-newsgroup-default-charset-alist))
55       )))
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 ((regexp-to-charset
67              (catch 'found
68                (let ((group
69                       (save-excursion
70                         (set-buffer gnus-summary-buffer)
71                         gnus-newsgroup-name))
72                      (alist gnus-newsgroup-default-charset-alist))
73                  (while alist
74                    (let ((pair (car alist)))
75                      (if (string-match (car pair) group)
76                          (throw 'found pair)
77                        ))
78                    (setq alist (cdr alist)))
79                  ))))
80         (if regexp-to-charset
81             (progn
82               (save-excursion
83                 (set-buffer gnus-summary-buffer)
84                 (make-local-variable 'default-mime-charset)
85                 (setq default-mime-charset (cdr regexp-to-charset)))
86               (make-local-variable 'default-mime-charset)
87               (setq default-mime-charset (cdr regexp-to-charset)))
88           (kill-local-variable 'default-mime-charset)))))
89
90
91 ;;; @ end
92 ;;;
93
94 (provide 'gnus-i18n)
95
96 ;;; gnus-i18n.el ends here