Contents

Internat

Internat is an internationalization module. It exports a simple interface to help implementing internationalization in applications. It works a little like i8n.

Synopsis

 >(require (planet "internat.scm" ("oesterholt" "internat.plt" 1 0)))
 >(define LANG-HASH (make-hash-table 'equal))
 > (internat-init (lambda (lang key default-translation)
                  (hash-table-get LANG-HASH (format "~a/~a" lang key) (lambda () default-translation)))
                (lambda (lang key translation)
                  (hash-table-put! LANG-HASH (format "~a/~a" lang key) translation))
                (lambda ()
                  (hash-table-map LANG-HASH (lambda (key val)
                                               (let ((kv (regexp-match "([^/]*)[/](.*)" key)))
                                                  (cdr kv)))))
                "en"
                (lambda (lang key)
                  (hash-table-remove! LANG-HASH (format "~a/~a" lang key))))
 > (internat-language! "nl")
 > (internat-language)
 "nl"
 > (internat-get "Hi?" )
 "Hi?"
 > (internat-set! "Hello?" "Hallo?")
 > (_ "Hello?")
 "Hallo?"
 > (internat-get "Hello?")
 "Hallo?"
 > (internat-translate "A book" "Een boek")
 > (internat-get "A book")
 "Een boek"
 > (internat-keys)
 ("A book" "Hello?")

API

(internat-init getter setter key-mapper language:string . deleter) : undefined

Initializes the internationalization module with the given mutation functions. A deleter function is optional, but if not given, it will result in an error if a key is removed.

(internat-language! language:string) : undefined

Sets the language to translate the input sentences to. Usually, one wants to use the mz-language-tags module to get IANA language tags for languages in combination with this function.

(internat-language) : string

Returns the current language.

(internat-get sentence) : string

Returns the translation for this sentence for the current language, or, if no translation is there, 'sentence' itself.

(_ sentence) : string

Same as 'internat-get'.

(internat-set! sentence translation) : undefined

Sets the translation for 'sentence' to 'translation' for the current language.

(internat-translate sentence translation) : undefined

Same as 'internat-set!'.

(internat-remove! sentence) : undefined

Removes the translation for 'sentence' for the current language.

(internat-keys) : (list of list of (language:string sentence:string)

Returns all language, sentence pairs in the current translation store. Can be used in translation applications (e.g. like internat-editor provided with this package).

Info

(p) 2005-2007 Hans Oesterholt-Dijkema, LGPL.