GNU Gettext for Clojure based on Easy i18n.
Gettext library is just a thin wrapper around Easy i18n for ease usage.
To install, add the following to you project :dependencies
:
[druids/gettext "0.2.0"]
And into :plugins
, if you want to call leiningen tasks.
Install a system dependency GNU Gettext.
A path for message files can be specified in project.clj
like:
{:gettext {:target-dir "resources/myproject/i18n"}
When the path is not specified following path is used: "resources/PROJECT_NAME/i18n".
Before you start a language file need to be initialized, e.g.:
lein gettext init cs ge
When translations are done, messages need to be merged:
lein gettext merge cs ge
And compiled into Java classes:
lein gettext compile cs ge
gettext.core
namespace provides following functions:
tr
a basic translate functiontrc
translates a string in the given contexttrf
a basic translate function within format abilitiestrcf
translate a message with context and argumentstrp
formats a string that varies based on plural formsExamples:
(require '[gettext.core :as gettext])
(gettext/tr "Hello") ;; Hello
(gettext/tr :de "Hello") ;; "Hallo"
(gettext/trf "Hello {0}" ["world"]) ;; "Hello world"
(gettext/trf :de "Hello {0}" ["Das Welt"]) ;; "Hallo Das Welt"
Currently extracting messages from Clojure code is NOT supported. This job has to be done by a hand.
Can you improve this documentation?Edit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close