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

Diff of /cl-l10n/i18n.lisp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by alendvai, Thu Jun 8 09:38:19 2006 UTC revision 1.6 by alendvai, Thu Jun 15 19:57:34 2006 UTC
# Line 84  implementation of that function Line 84  implementation of that function
84                  collect `(add-resource ,locale-name                  collect `(add-resource ,locale-name
85                            ',(first resource) ',(second resource) ',(cddr resource))))))                            ',(first resource) ',(second resource) ',(cddr resource))))))
86    
87    (defmacro lookup-first-matching-resource (&body specs)
88      "Try to look up the resource keys, return the first match, fallback to the first key.
89    An example usage:
90      (lookup-first-matching-resource
91        ((awhen attribute (name-of it)) (name-of state))
92        ((name-of (state-machine-of state)) (name-of state))
93        (\"state-name\" (name-of state))
94        \"last-try\")
95    When a resource key is a list, its elements will be concatenated separated by dots."
96      (iter (with fallback = nil)
97            (for spec in specs)
98            (for el = (if (or (and (consp spec)
99                                   (symbolp (car spec)))
100                              (atom spec))
101                          spec
102                          `(strcat-separated-by "." ,@spec)))
103            (if (first-time-p)
104                (setf fallback el)
105                (collect `(lookup-resource ,el nil :warn-if-missing nil :fallback-to-name nil) into lookups))
106            (finally (return (with-unique-names (block fallback-tmp)
107                               `(block ,block
108                                 (let ((,fallback-tmp ,fallback))
109                                   (bind (((values resource foundp) (lookup-resource
110                                                                     ,fallback-tmp nil :warn-if-missing nil :fallback-to-name nil)))
111                                     (when foundp
112                                       (return-from ,block (values resource t))))
113                                   ,@(iter (for lookup in lookups)
114                                           (collect `(bind (((values resource foundp) ,lookup))
115                                                      (when foundp
116                                                        (return-from ,block (values resource t))))))
117                                   (return-from ,block (values ,fallback-tmp nil)))))))))
118    
119  (defmacro enable-sharpquote-reader ()  (defmacro enable-sharpquote-reader ()
120    "Enable quote reader for the rest of the file (being loaded or compiled).    "Enable quote reader for the rest of the file (being loaded or compiled).
121  #\"my i18n text\" parts will be replaced by a lookup-resource call for the string.  #\"my i18n text\" parts will be replaced by a lookup-resource call for the string.

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.5