Hi,

We're developing a Weblocks application, and we need all texts to be in
the proper language, i.e. based on Accept-Language HTTP header.

What follows are the relevant parts of our approach so far:

(defvar *user-messages* (make-hash-table :test 'equal))

(defun get-request-language (...))

(defclass web-page-messages ()
  ((page :accessor page-name
         :initarg :name)
   (messages :accessor messages
             :initform (make-hash-table :test 'equal)))) ;;
;; The page's messages: a hash map (message key + ISO code language
;; -> localized message


(defmethod get-message ((page web-page-messages) message-key language)
  (multiple-value-bind (message outcome)
      (gethash (build-hashkey message-key language) (messages page))
    message))

(defmethod get-message (other message-key language)
  message-key)

(defmethod add-message ((page web-page-messages) message-key language
text) (setf (gethash (build-hashkey message-key language) (messages
page)) text))

(defun build-hashkey (message-key language)
  (concatenate 'string message-key "-" language))

(defun get-page-messages (name)
  (multiple-value-bind (page outcome)
      (gethash name *user-messages*)
    page))

(defun build-user-messages ()
  (progn
    (setf (gethash "XX" *user-messages*) (build-XX-messages))
    (setf (gethash "YY" *user-messages*) (build-YY-messages))
    )
  )

(defun build-XX-messages ()
  (let ((page (make-instance 'web-page-messages :name "XX")))
    (add-message page "print" "es" "Imprimir")
    (add-message page "print" "en" "Print")
    )
  )


Then, we translate each hard-coded text TXT with

(get-message (get-page-messages "XX") "TXT" (get-request-language))


We have two problems with this approach:

1) All texts in our defviews (using :label) are computed at application
start-up, and they don't get new values afterwards.
2) It seems the defvar for *user-messages* is invalid. It doesn't get
filled with the new values unless I execute the logic manually in
slime. I don't find a reason for this behavior. That's the point of the
(get-message (other ..)) method: to continue when the web-page-messages
instance is not found.

I assume I'm using bad habits and probably overlooking trivial details.
Any suggestion is very much appreciated.

Kind regards,
Jose.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"weblocks" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/weblocks?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to