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-headershould be the value of an RFC2616Accept-Languageheader.
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-specshould be either a map as generated bygenerate-accept-languages, or else a string;resource-pathshould 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.
tokenshould be a clojure keyword identifying the message to be retrieved;accept-language-headershould be the value of an RFC2616Accept-Languageheader;resource-pathshould be the fully-qualified path name of the directory in which message files are stored;default-localeshould 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-headershould be the value of an RFC2616Accept-Languageheader;resource-pathshould be the fully-qualified path name of the directory in which message files are stored;default-localeshould 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-headershould be the value of an RFC2616Accept-Languageheader;resource-pathshould be the fully-qualified path name of the directory in which message files are stored;default-localeshould 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.