language.el 1.64 KB
Newer Older
Niels Möller's avatar
Niels Möller committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

(defconst lyskom-category-properties
  '((command . lyskom-command)
    (menu    . lyskom-menu)
    (message . lyskom-message))
  "Property names for saving different categories.")

(defun lyskom-define-language (category language alist)
  "Associates names to symbols.

CATEGORY and LANGUAGE determines what kind of association to
create. ALIST is a mapping from symbols to strings."
  (let ((property (cdr (assq category lyskom-category-properties))))
    (mapcar (function (lambda (pair)
			(let* ((symbol (car pair))
			       (string (cdr pair))
			       (llist (get symbol property))
			       (entry (assq language llist)))
			  (if entry (setcdr entry string)
			    (put symbol property
				 (cons (cons language string) llist))))))
	    alist)))

(put 'lyskom-define-language 'lisp-indent-function 2)

(defun lyskom-get-string (symbol &optional category)
  "Returns string assiciated with SYMBOL"
  (if (not category) (setq category 'message))
  (let ((prop (cond ((eq category 'command)
		     (get symbol 'lyskom-command))
		    ((eq category 'menu)
		     (or (get symbol 'lyskom-menu)
			 (get symbol 'lyskom-command)))
		    ((eq category 'message)
		     (get symbol 'lyskom-message))
		    (t nil))))
    (or (cdr (assq lyskom-language prop))
	(signal 'lyskom-internal-error 
		(list 'lyskom-get-string
		      (list symbol category ": string not found"))))))

(defun lyskom-get-strings (symbols &optional category)
  "Returns an alist of (symbol . string) pairs

according to CATEGORY and lyskom-language. Sort of inverse to
lyskom-define-language."
  (mapcar (function (lambda (symbol)
		      (cons symbol (lyskom-get-string symbol category))))
	  symbols))