API | Wiki | Latest releases | Slack channel
Tempura is mature, developer-friendly library for supporting multilingual text in your Clojure and ClojureScript applications.
It offers a simple, easy-to-use API that allows you to expand localization content over time, without bogging down early development.
2024-06-05
v1.5.4
: release info
See here for earlier releases.
- Tiny (single fn), cross-platform all-Clojure API for providing multilingual text content.
- Matches gettext's convenience for embedding default content directly in code (optional).
- Exceeds gettext's ability to handle versioned content through unique content ids.
- Works out-the-box with plain text, Hiccup, Reactjs, etc.
- Easy, optional platform-appropriate support for simple Markdown styles.
- Flexibility: completely open/pluggable resource compiler.
- Performance: match or exceed
format
performance through compilation + smart caching. - All-Clojure (edn) dictionary format for ease of use, easy compile-and-runtime manipulation, etc.
- Focused on common-case translation and no other aspects of i18n/L10n.
(require '[taoensso.tempura :as tempura :refer [tr]]))
(tr ; For "translate"
{:dict ; Dictionary of translations
{:sw {:missing "sw/?" :r1 "sw/r1" :r2 "sw/r2"}
:en {:missing "en/?" :r1 "en/r1" :r2 "en/r2"}}}
[:sw :en <...>] ; Locales (desc priority)
[:r1 :r2 <...> ; Resources (desc priority)
<?fallback-str> ; Optional final fallback string
])
;; =>
(or
sw/r1 sw/r2 <...> ; Descending-priority resources in priority-1 locale
en/r1 en/r2 <...> ; '' in priority-2 locale
<...>
?fallback-str ; Optional fallback string (as last element in resources vec)
sw/? ; Missing (error) resource in priority-1 locale
en/? ; '' priority-2 locale
nil ; If none of the above exist
)
;; etc.
;; Note that ?fallback-str is super handy for development before you
;; have translations ready, e.g.:
(tr {:dict {}} [:en] [:sign-in-btn "Sign in here!"])
;; => "Sign in here!"
;; Tempura also supports Hiccup with Markdown-like styles, e.g.:
(tr {:dict {}} [:en] [:sign-in-btn ["**Sign in** here!"]])
;; => [:span [:strong "Sign in"] " here!"]
- Wiki (getting started, usage, etc.)
- API reference: cljdoc, Codox
- Support: Slack channel or GitHub issues
You can help support continued work on this project, thank you!! 🙏
Copyright © 2016-2024 Peter Taoussanis.
Licensed under EPL 1.0 (same as Clojure).