scot.weft.i18n.core
Internationalisation.
*resource-path*
dynamic
The default path within the resources space on which translation files will be sought.
acceptable-languages
(acceptable-languages accept-language-header)
Generate an ordered list of acceptable languages, most-preferred first.
accept-language-header
should be the value of an RFC2616Accept-Language
header.
Returns a list of maps as generated by generate-accept-languages
, in descending order of preference.
find-language-file-name
(find-language-file-name language-spec resource-path)
Find the name of a messages file on this resource path which matches this language-spec
.
language-spec
should be either a map as generated bygenerate-accept-languages
, or else a string;resource-path
should be the path name of the directory in which message files are stored, within the resources on the classpath.
Returns the name of an appropriate file if any is found, else nil.
generate-accept-languages
(generate-accept-languages parse-tree)
From a parse-tree
generated by the language-specifier-grammar
, generate a list of maps each having a :language
key, a :preference
key and a :qualifier
key.
get-message
Return the message keyed by this token
from the most acceptable messages collection
we have given this accept-language-header
.
token
should be a clojure keyword identifying the message to be retrieved;accept-language-header
should be the value of an RFC2616Accept-Language
header;resource-path
should be the fully-qualified path name of the directory in which message files are stored;default-locale
should be a locale specifier to use if no acceptable locale can be identified.
get-messages
Return the most acceptable messages collection we have given this accept-language-header
accept-language-header
should be the value of an RFC2616Accept-Language
header;resource-path
should be the fully-qualified path name of the directory in which message files are stored;default-locale
should be a locale specifier to use if no acceptable locale can be identified.
Returns a map of message keys to strings.; if no useable file is found, returns nil.
raw-get-messages
(raw-get-messages accept-language-header resource-path default-locale)
Return the most acceptable messages collection we have given this accept-language-header
. Do not use this function directly, use the memoized variant get-messages
, as performance will be very much better.
accept-language-header
should be the value of an RFC2616Accept-Language
header;resource-path
should be the fully-qualified path name of the directory in which message files are stored;default-locale
should be a locale specifier to use if no acceptable locale can be identified.
Returns a map of message keys to strings; if no useable file is found, returns nil.
slurp-resource
(slurp-resource name)
Slurp the resource of this name and return its contents as a string; but if it doesn’t exist log the fact and return nil, rather than throwing an exception.