/[cl-l10n]/cl-l10n/i18n.lisp
ViewVC logotype

Contents of /cl-l10n/i18n.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations)
Thu Apr 27 18:30:30 2006 UTC (7 years, 11 months ago) by sross
Branch: MAIN
CVS Tags: before_i18n_rewrite
Changes since 1.3: +1 -1 lines
* parse-number.lisp: Changed parse-error to extend parser-error
* parse-time.lisp: Changed uses of eq to eql when using numbers
  or characters.
* printers.lisp: Default length fraction digits to 0 if it can't
  be found in the current locale. Fixed printers of %R time format directive.
* load-locale.lisp: Search environment variable LANG before trying using
  POSIX locale when loading default locale.
  Add shadowing-format which shadows format and formatter into the current package.
* package.lisp: Export load-default-locale
* doc/cl-l10n.texi: Rename the Index node to Comprehensive Index in
  order to avoid a name clash with index.html on platforms with
  case-insensitive filesystems.  Prettify the copyright notice.
* doc/Makefile, doc/style.css, doc/gendocs.sh, doc/gendocs_template, doc/style.css:
  New files.
* load-locale.lisp (load-locale): Specify an explicit
  external-format for CLISP
* test.lisp: Fix indentation of deftest forms.
  (time.2): Obtain the o-with-diaeresis in a slightly more portable way.
1 ;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;; See the file LICENCE for licence information.
3 (in-package :cl-l10n)
4
5
6 ;; (defparameter bundle (make-instance 'bundle))
7
8 ;; (add-resources (bundle "af_")
9 ;; "showtime" "Dankie, die tyd is ~:@U~%")
10
11 ;; ;; an empty string as the locale matcher becomes the default
12 ;; (add-resources (bundle "")
13 ;; "showtime" "Thanks, the time is ~:@U~%")
14
15 ;; (set-dispatch-macro-character
16 ;; #\# #\i
17 ;; #'(lambda (s c1 c2)
18 ;; (declare (ignore c2))
19 ;; `(cl-l10n:gettext ,(read s) bundle)))
20
21 ;; or this
22 ;; (defmacro _ (text)
23 ;; `(cl-l10n:gettext ,text bundle))
24
25 ;; (defun timey ()
26 ;; (format t #i"showtime" (get-universal-time)))
27
28 (defclass bundle ()
29 ((resources :accessor resources :initform (make-hash-table :test #'equal))))
30
31 (defgeneric add-resource (bundle from to lang))
32 (defmethod add-resource (bundle from to lang)
33 (aif (assoc lang (gethash from (resources bundle)) :test #'equal)
34 (setf (cdr it) to)
35 (pushnew (cons lang to) (gethash from (resources bundle))
36 :test #'equal))
37 t)
38
39 (defmacro add-resources ((bundle loc-name) &body args)
40 (with-gensyms (gloc gbundle)
41 `(let ((,gloc ,loc-name) (,gbundle ,bundle))
42 ,@(mapcar #'(lambda (x) `(add-resource ,gbundle ,@x ,gloc))
43 (group args 2)))))
44
45 (defgeneric get-name (bundle name)
46 (:method ((bundle t) (name t))
47 (gethash name (resources bundle))))
48
49 (defgeneric lookup-name (bundle name)
50 (:method ((bundle t) (name t))
51 (when-let (name (get-name bundle name))
52 ;; The match with the longest name is the most
53 ;; specific key.
54 (winner #'>
55 (load-time-value (compose #'length #'car))
56 (remove-if-not #'(lambda (x)
57 (search (car x)
58 (locale-name *locale*)))
59 name)))))
60
61 (defun gettext (name bundle &optional (loc *locale*))
62 (let ((*locale* (locale-des->locale loc)))
63 (or (cdr (lookup-name bundle name))
64 name)))
65
66
67
68
69 ;; EOF

  ViewVC Help
Powered by ViewVC 1.1.5