Changeset 3286
- Timestamp:
- 06/17/08 14:01:20 (7 months ago)
- Files:
-
- trunk/projects/bos/payment-website/templates/da/dictionary.xml (modified) (1 diff)
- trunk/projects/bos/payment-website/templates/de/dictionary.xml (modified) (1 diff)
- trunk/projects/bos/payment-website/templates/en/dictionary.xml (modified) (1 diff)
- trunk/projects/bos/web/dictionary.lisp (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/projects/bos/payment-website/templates/da/dictionary.xml
r3275 r3286 1 <?xml version="1.0" encoding="UTF-8"?> 2 1 3 <dictionary> 2 <title>ein dÀnischer titel</title> 3 <description>eine dÀnische beschreibung</description> 4 <!-- in /tmp/ttt.lisp 5 /tmp/ttt2.lisp --> 6 <entry> 7 <key> 8 hallo wie gehts? 9 </key> 10 <value> 11 </value> 12 </entry> 13 <!-- in /tmp/ttt.lisp --> 14 <entry> 15 <key> 16 na? 17 </key> 18 <value> 19 </value> 20 </entry> 21 <!-- in NIL --> 22 <entry> 23 <key> 24 test 25 </key> 26 <value> 27 </value> 28 </entry> 4 29 </dictionary> trunk/projects/bos/payment-website/templates/de/dictionary.xml
r3275 r3286 1 <?xml version="1.0" encoding="UTF-8"?> 2 1 3 <dictionary> 2 <title>meint titel</title> 3 <description>meine beschreibung</description> 4 <!-- in /tmp/ttt.lisp 5 /tmp/ttt2.lisp --> 6 <entry> 7 <key> 8 hallo wie gehts? 9 </key> 10 <value> 11 </value> 12 </entry> 13 <!-- in /tmp/ttt.lisp --> 14 <entry> 15 <key> 16 na? 17 </key> 18 <value> 19 </value> 20 </entry> 21 <!-- in NIL --> 22 <entry> 23 <key> 24 test 25 </key> 26 <value> 27 </value> 28 </entry> 4 29 </dictionary> trunk/projects/bos/payment-website/templates/en/dictionary.xml
r3275 r3286 1 <?xml version="1.0" encoding="UTF-8"?> 2 1 3 <dictionary> 2 4 <!-- in /tmp/ttt.lisp 5 /tmp/ttt2.lisp --> 6 <entry> 7 <key> 8 hallo wie gehts? 9 </key> 10 <value> 11 hi, how are you? 12 </value> 13 </entry> 14 <!-- in /tmp/ttt.lisp --> 15 <entry> 16 <key> 17 na? 18 </key> 19 <value> 20 </value> 21 </entry> 22 <!-- in NIL --> 23 <entry> 24 <key> 25 test 26 </key> 27 <value> 28 </value> 29 </entry> 3 30 </dictionary> trunk/projects/bos/web/dictionary.lisp
r3285 r3286 3 3 (defvar *dictionary* (make-hash-table :test #'equal)) 4 4 (defvar *dictionary-last-reads-alist* nil) 5 (defvar *dictionary-keys* nil 6 "An alist of key compile-file-pathnames pairs that is 7 automatically build at compile-time from all occurences of 8 DICTIONARY-ENTRY in user-code.") 5 9 6 (def parameter *dictionary-directory* *website-directory*10 (defmacro dictionary-directory () 7 11 "The xml files containing dictionary definitions for a 8 12 particular language are stored under 9 *dictionary-directory*/<language>/dictionary.xml.") 13 (dictionary-directory)/<language>/dictionary.xml." 14 '*website-directory*) 10 15 11 16 (deftype dictionary-language () … … 21 26 (keyword language-designator))) 22 27 23 (defun dictionary-entry (key language) 28 (defun dictionary-key-occurences (key) 29 (cdr (assoc key *dictionary-keys* :test #'string=))) 30 31 (defun (setf dictionary-key-occurences) (value key) 32 (let ((cons (assoc key *dictionary-keys* :test #'string=))) 33 (if cons 34 (rplacd cons value) 35 (push (cons key value) *dictionary-keys*)))) 36 37 (defun %dictionary-entry (key language) 24 38 (let ((language (dictionary-language language))) 25 39 (load-dictionary-if-needed language) … … 27 41 key))) 28 42 29 (defun (setf dictionary-entry) (value key language)43 (defun (setf %dictionary-entry) (value key language) 30 44 (let* ((language (dictionary-language language)) 31 45 (it (assoc language (gethash key *dictionary*)))) … … 33 47 (rplacd it value) 34 48 (push (cons language value) (gethash key *dictionary*))))) 49 50 (defmacro dictionary-entry (key language) 51 (flet ((pathname-equal (a b) 52 (equal (namestring a) (namestring b)))) 53 (check-type key string) 54 (when *compile-file-pathname* 55 (pushnew *compile-file-pathname* (dictionary-key-occurences key) 56 :test #'pathname-equal)) 57 `(%dictionary-entry ,key ,language))) 35 58 36 59 (defun dictionary-clear-entries-by-language (language) … … 61 84 :type "xml" 62 85 :directory (list :relative "templates" (string-downcase (string language)))) 63 *dictionary-directory*))86 (dictionary-directory))) 64 87 65 88 (defun load-dictionary (language xml-path) 66 89 (declare (dictionary-language language)) 67 (labels ((load-language (language xml-path) 90 (labels ((trim-whitespace (string) 91 (string-trim '(#\space #\newline #\tab) string)) 92 (load-language (language xml-path) 68 93 (handler-case 69 94 (let ((xmls (cxml:parse-file xml-path (cxml-xmls:make-xmls-builder)))) … … 71 96 "root element should be \"dictionary\"") 72 97 (dolist (element (cxml-xmls:node-children xmls)) 73 (when (consp element) 74 (let ((key (cxml-xmls:node-name element)) 75 (value (first (cxml-xmls:node-children element)))) 76 (assert (or (null value) (stringp value))) 77 (when value 78 (setf (dictionary-entry key language) value)))))) 98 (when (consp element) 99 (assert (equal "entry" (cxml-xmls:node-name element)) nil 100 "expected element \"entry\"") 101 (let ((key-value (remove-if #'atom (cxml-xmls:node-children element)))) 102 (assert (equal "key" (cxml-xmls:node-name (first key-value))) nil 103 "expected element \"key\"") 104 (assert (equal "value" (cxml-xmls:node-name (second key-value))) nil 105 "expected element \"value\"") 106 (let ((key (trim-whitespace (first (cxml-xmls:node-children (first key-value))))) 107 (value (trim-whitespace (first (cxml-xmls:node-children (second key-value)))))) 108 (assert (stringp key)) 109 (assert (stringp value)) 110 (unless (zerop (length value)) 111 (setf (%dictionary-entry key language) value))))))) 79 112 (error (c) 80 113 (error "Error while loading ~a:~%~a" 81 (enough-namestring xml-path *dictionary-directory*) c)))))114 (enough-namestring xml-path (dictionary-directory)) c))))) 82 115 (dictionary-clear-entries-by-language language) 83 116 (load-language language xml-path) … … 92 125 (load-dictionary language xml-path)))) 93 126 127 (defun dictionary-write-template (&optional (stream *standard-output*)) 128 (cxml:with-xml-output (make-character-stream-sink stream :canonical nil :indentation 2) 129 (with-element "dictionary" 130 (loop for (key . paths) in (sort (copy-list *dictionary-keys*) #'string< :key #'car) 131 do (cxml:comment (format nil " in ~A ~{~%~8T~A ~}" (first paths) (rest paths))) 132 do (with-element "entry" 133 (with-element "key" (text key)) 134 (with-element "value" (text ""))))))) 135
