declare-bundle!

[procedure] declare-bundle! bundle-specifier alist

SRFI-29: Used to prepare a bundle for srfi-29 based localization. Declares a new bundle named by the given bundle-specifier. The contents of the bundle are defined by alist, which is an assoc list of Scheme symbol and message template (string).

The declared bundle may be saved in implementation-specific format by store-bundle. Once stored, an application can load the bundle by load-bundle!, then use localized-template to obtain a message template according to the current locale settings (e.g. current-language, current-country, and current-locale-details).

The following example is taken from srfi-29 document:

(let ((translations
       '(((en) . ((time . "Its ~a, ~a.")
                (goodbye . "Goodbye, ~a.")))
         ((fr) . ((time . "~1@*~a, c'est ~a.")
                (goodbye . "Au revoir, ~a."))))))
  (for-each (lambda (translation)
              (let ((bundle-name (cons 'hello-program (car translation))))
                (if (not (load-bundle! bundle-name))
                    (begin
                     (declare-bundle! bundle-name (cdr translation))
                     (store-bundle! bundle-name)))))
             translations))

(define localized-message
  (lambda (message-name . args)
    (apply format (cons (localized-template 'hello-program
                                            message-name)
                        args))))

(let ((myname "Fred"))
  (display (localized-message 'time "12:00" myname))
  (display #\newline)

  (display (localized-message 'goodbye myname))
  (display #\newline))

;; Displays (English):
;; Its 12:00, Fred.
;; Goodbye, Fred.
;;
;; French:
;; Fred, c'est 12:00.
;; Au revoir, Fred.