taoensso.tempura
Pure Clojure/Script i18n translations library.
get-default-resource-compiler
cljs
(get-default-resource-compiler {:keys [default-tag escape-html? experimental/compact-vectors?], :or {default-tag :span}})
Implementation detail.
Good general-purpose resource compiler.
Supports output of text, and Hiccup forms with simple Markdown styles.
new-tr-fn
cljs
(new-tr-fn opts)
Returns a new translate ("tr") function,
(fn tr [locales resource-ids ?resource-args]) -> translation.
Common opts:
:default-locale ; Optional fallback locale to try when given locales don't
; have the requested resource/s.
; Default is `:en`.
:dict ; Dictionary map of resources,
; {<locale> {<k1> ... {<kn> <resource>}}}.
; See `tempura/example-dictionary` for more info.
:resource-compiler ; (fn [resource]) -> <(fn [vargs]) -> <compiled-resource>>.
; Useful if you want to customize any part of how
; dictionary resources are compiled.
:missing-resource-fn ; (fn [{:keys [opts locales resource-ids resource-args]}]).
; Called when requested resource/s cannot be found. Useful
; for logging, etc. May return a non-nil fallback resource
; value.
:cache-dict? ; Cache dictionary compilation? Improves performance,
; usually safe. You probably want this enabled in
; production, though you might want it disabled in
; development if you use `:__load-resource` dictionary
; imports and want resource changes to automatically
; reflect.
;
; Default is `false` for Clj and `:global` for Cljs.
:cache-locales? ; Cache locales processing? Improves performance, safe iff
; the returned `tr` fn will see a limited number of unique
; `locales` arguments (common example: calling
; `tempura/new-tr-fn` for each Ring request).
;
; Default is `false` for Clj and `:global` for Cljs.
:cache-resources? ; Cache resource lookup? Improves performance but will use
; memory for every unique combination of `locales` and
; `resource-ids`. Safe only if these are limited in number.
;
; Default is `false`.
Possible values for `:cach-<x>` options:
falsey ; Use no cache
`:fn-local` ; Use a cache local to the returned `tr` fn
`:global`/truthy ; Use a cache shared among all `tr` fns with `:global` cache
Example:
;; Define a tr fn
(def my-tr ; (fn [locales resource-ids ?resource-args]) -> translation
(new-tr-fn
{:dict
{:en {:missing "Missing translation"
:example {:greet "Hello %1"
:farewell "Goodbye %1, it was nice to meet you!"}}}}))
;; Then call it
(my-tr
[:fr-FR :en-GB-variation1] ; Descending-preference locales to try
;; Descending-preference dictionary resorces to try.
;; May contain a final non-keyword fallback:
[:example/how-are-you? "How are you, %1?"]
;; Optional arbitrary args for insertion into compiled resource:
["Steve"])
=> "How are you, Steve?"
See `tempura/default-tr-opts` for detailed default options.
See also `tempura/tr`.
For further info & examples, Ref.
https://github.com/ptaoussanis/tempura and
https://github.com/ptaoussanis/tempura/wiki/Tempura-documentation
tr
cljs
(tr opts locales resource-ids)
(tr opts locales resource-ids resource-args)
Translate ("tr") function,
(fn tr [opts locales resource-ids ?resource-args]) -> translation.
See `tempura/new-tr-fn` for full documentation, and for fn-local caching.