doc | ||
resources/i18n | ||
src/scot/weft/i18n | ||
test/scot/weft/i18n/test | ||
.gitignore | ||
CHANGELOG.md | ||
LICENSE | ||
project.clj | ||
README.md |
internationalisation
A Clojure library designed to provide simple interationalisation of user-facing messages.
Usage
To use this library in your project, add the following leiningen dependency:
[org.clojars.simon_brooke/internationalisation "1.0.0"]
To use it in your namespace, require:
[scot.weft.i18n.core :refer [get-messages]]
There is only one function you should need to use:
get-messages
(get-messages accept-language-header resource-path default-locale)
Return the most acceptable messages collection we have given this accept-language-header. Use this function instrad of the unmemoized variant raw-get-messages, as performance will be very much better.
accept-language-header
should be the value of an RFC 2616 Accept-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.
See RFC 2616.
The translation files
Obviously, this only works if you provide files with translations of your interesting strings. These files should contain Clojure maps, and the file names should be the locale string for which the file is relevent followed by the extension ".edn". All the translation files should be in the same directory.
In this project you will find two very simple example files, which should give you the idea:
en-GB.edn
;;;; This is a British English translation file.
{:pipe "This is not a pipe"}
fr-FR.edn
;;;; This is a French translation file.
{:pipe "Ceci n'est pas une pipe."}
Documentation
Documentation may be generated by running
lein codox
License
Copyright © 2017 Simon Brooke
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.