1 ;;; chess-message.el --- Code shared by all chess displays
3 ;; Copyright (C) 2014 Free Software Foundation, Inc.
5 ;; This is free software; you can redistribute it and/or modify it under
6 ;; the terms of the GNU General Public License as published by the Free
7 ;; Software Foundation; either version 3, or (at your option) any later
10 ;; This is distributed in the hope that it will be useful, but WITHOUT
11 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 ;; You should have received a copy of the GNU General Public License
16 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
22 (defgroup chess-message nil
23 "Support for message catalogs in chess.el."
26 (defcustom chess-message-language 'english
27 "The language to use when reporting messages."
29 :group 'chess-message)
33 (defvar chess-message-catalog nil)
35 (defun chess-message-catalog (catalog definitions)
36 (let ((entry (assq catalog chess-message-catalog)))
38 (dolist (def definitions)
39 (let ((str (assq (car def) (cdr entry))))
41 (setcdr str (cdr def))
42 (setcdr entry (cons def (cdr entry))))))
43 (push (cons catalog definitions) chess-message-catalog))))
45 (defun chess-string (key &rest arguments)
46 (let* ((entry (assq chess-message-language chess-message-catalog))
47 (msg (and entry (cdr (assq key (cdr entry))))))
49 (apply 'format msg arguments)
50 (format "Message not found: %s" key))))
52 (defsubst chess-message (key &rest arguments)
53 (message (apply 'chess-string key arguments)))
55 (defsubst chess-error (key &rest arguments)
56 (error (apply 'chess-string key arguments)))
58 (put 'chess-message-catalog 'lisp-indent-function 1)
60 (provide 'chess-message)
62 ;;; chess-message.el ends here