16 Localization
(require koyo/l10n) | package: koyo-lib |
This module provides a middleware and facilities for localizing messages.
parameter
(current-locale-specifier spec) → void? spec : symbol?
parameter
(current-locales) → (listof (cons/c symbol? symbol?))
(current-locales locales) → void? locales : (listof (cons/c symbol? symbol?))
procedure
(load-locales! path) → void?
path : path-string?
The directory must have one subdirectory per language and each language subdirectory must contain one translation file per region.
For example, for English, one might define the following structure:
"resources/locales/en/"
"resources/locales/en/uk.rktd"
"resources/locales/en/us.rktd"
Each translation file must contain a list of pairs where the first element is a symbol and the second is the translation format string for that symbol. For example:
((title . "Bogdan's Blog") (subtitle . "Just another one of these things") (hello . "Hi, ~a!"))
If there is no translation named message-name then message-name is converted to a string and the args are ignored.
(translate 'title) (translate 'hello "Jim")
procedure
((wrap-browser-locale sessions) handler)
→ (-> request? can-be-response?) sessions : session-manager? handler : (-> request? can-be-response?)
If 'l10n.lang is present in the current user’s session then that value takes precedence over the value of the Accept-Language header.