[Bese-devel] i18n

Evrim ULU evrim at core.gen.tr
Mon Mar 13 04:34:47 UTC 2006


Hi Marco,

What do you think about this i18n trial with cl-l10n? I have used
cl-l10n as drew suggested.

---------cut------------
;;; load locales
(load-all-locales)

(defparameter *coretal-bundle* (make-instance 'bundle))

(defparameter *default-locale* (locale "tr_TR"))

;;; use with #"my i18n text" -evrim
(set-dispatch-macro-character
 #\# #\"
 #'(lambda (s c1 c2)
     (declare (ignore c2))
     (unread-char c1 s)
     `(cl-l10n:gettext ,(read s) *coretal-bundle*
               (if (not (eq *context* :unbound))
                 (ucw::context.locale *context*)
               *default-locale*))))

(defun add-text (lang from to)
  (add-resource *coretal-bundle* from to lang))

(defun add-text-en (from to)
  (add-text "en_US" from to))

(defun add-text-tr (from to)
  (add-text "tr_TR" from to))

;;; start bundling strings
;;; (add-text-tr "" "")

(add-text-tr "Sample Title" "Örnek Başlık")
---------cut------------
---------cut------------
(in-package :ucw)

(defclass i18n-cookie-application (cookie-session-application)
  ((default-locale-id :initarg :default-locale-id :accessor
application.default-locale-id)
   (accepted-locales :initarg :accepted-locales :accessor
application.accepted-locales
             :initform '())))

(defclass i18n-cookie-request-context (cookie-session-request-context)
  ((locale :accessor context.locale :initarg :locale :initform nil)))

(defmethod make-request-context ((app i18n-cookie-application)
                 (request request)
                 (response response))

  (make-instance 'i18n-cookie-request-context
         :request request
         :response response
         :application app
         :locale (or (process-accept-language app request)
                 (application.default-locale-id app))))

(defmethod process-accept-language ((app i18n-cookie-application)
(request request))
  (awhen (get-header request :accept-language)
    (let ((langs (parse-accept-language-header it)))
      (dolist (l langs)
        ;; first we check for an exact match
        (when (member (cl-l10n::locale (first l) :errorp nil)
(application.accepted-locales app) :test #'eq)
          (return-from process-accept-language (cl-l10n::locale (first
l) :errorp nil)))
        (when (= 2 (length (first l)))
          ;; they asked for a language without suppyling a script, see
          ;; if we provied a language of that script.
          (dolist (a (application.accepted-locales app))
        (when (string= (first l) (subseq (slot-value a
'cl-l10n::locale-name) 0 2))
              (return-from process-accept-language a))))))))

(in-package :some-other-package)

(defclass core-application (ucw::i18n-cookie-application
secure-application-mixin)
  ((coretal :accessor core-application.coretal
        :initarg :coretal
        :initform (error "Could not instantanize core-application
without 'coretal' instance.")
        :documentation "Coretal Object")
   (module-base :accessor core-application.module-base
        :initarg :module-base
        :initform (make-instance 'coretal-module-base)
        :documentation "module-base object holds module information"))
  (:default-initargs
    :default-locale-id *default-locale*
    :accepted-locales (list *default-locale* (locale "en_US"))))
---------cut------------



More information about the bese-devel mailing list