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 infoSee here for earlier releases.
format
performance through compilation + smart caching.(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!"]
You can help support continued work on this project, thank you!! 🙏
Copyright © 2016-2024 Peter Taoussanis.
Licensed under EPL 1.0 (same as Clojure).
Can you improve this documentation? These fine people already did:
Peter Taoussanis & Ryan FowlerEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close