Liking cljdoc? Tell your friends :D

taoensso.tempura

Pure Clojure/Script i18n translations library.

Pure Clojure/Script i18n translations library.
raw docstring

*tr-opts*clj/s

source

*tr-scope*clj/s

source

default-tr-optsclj/s

source

example-dictionaryclj/s

source

load-resource-at-compile-timeclj/smacro

(load-resource-at-compile-time rname)

Experimental, subject to change. Reads and inlines an edn resource on classpath, at compile-time. Supported by: both clj and cljs.

See also load-resource-at-runtime.

Experimental, subject to change.
Reads and inlines an edn resource on classpath, at compile-time.
Supported by: both clj and cljs.

See also `load-resource-at-runtime`.
source (clj)source (cljs)raw docstring

load-resource-at-runtimeclj

(load-resource-at-runtime rname)

Experimental, subject to change. Reads and returns an edn resource on classpath, at runtime. Supported by: clj only (cljs support not possible).

A {:my-key {:__load-resource "my-file.edn"}} dictionary entry is equivalent to {:my-key (load-resource-at-runtime "my-file.edn")}.

See also load-resource-at-compile-time.

Experimental, subject to change.
Reads and returns an edn resource on classpath, at runtime.
Supported by: clj only (cljs support not possible).

A {:my-key {:__load-resource "my-file.edn"}} dictionary entry is
equivalent to {:my-key (load-resource-at-runtime "my-file.edn")}.

See also `load-resource-at-compile-time`.
sourceraw docstring

parse-http-accept-headerclj

(parse-http-accept-header header)

Parses given HTTP Accept header string and returns ordered vector of choices. No auto normalization. Ref. https://goo.gl/c4ClkR.

Parses given HTTP Accept header string and returns ordered vector
of choices. No auto normalization. Ref. https://goo.gl/c4ClkR.
sourceraw docstring

trclj/s

(tr opts locales resource-ids)
(tr opts locales resource-ids resource-args)

Next gen Taoensso (tr)anslation API:

(tr ;; Opts map to control behaviour: {:default-locale :en :dict ; Resource dictionary {:en {:missing "Missing translation" :example {:greet "Hello %1" :farewell "Goodbye %1, it was nice to meet you!"}}}}

;; Descending-preference locales to try: [:fr-FR :en-GB-variation1]

;; 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?"

Common opts (see tempura/default-tr-opts for default vals):

:default-locale ; Optional fallback locale to try when given ; locales don't have the requested resource/s.

:dict ; Dictionary map of resources, ; {<locale> {<k1> ... {<kn> <resource>}}}. ; See also tempura/example-dictionary.

: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? ; Only reason you'd want this off is if ; you're using :__load-resource imports and ; and want dictionary to pick up changes.

:cache-locales? ; Client will usu. be dealing with a small ; number of locales, the server often a ; large number in the general case. tr ; partials may want to enable cached locale ; expansion (e.g. in the context of a ; particular user's Ring request, etc.).

:cache-resources? ; For the very highest possible performance ; when using a limited domain of locales + ; resource ids.

Next gen Taoensso (tr)anslation API:

(tr
  ;; Opts map to control behaviour:
  {:default-locale :en
   :dict ; Resource dictionary
   {:en {:missing "Missing translation"
         :example {:greet "Hello %1"
                   :farewell "Goodbye %1, it was nice to meet you!"}}}}

  ;; Descending-preference locales to try:
  [:fr-FR :en-GB-variation1]

  ;; 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?"


Common opts (see `tempura/default-tr-opts` for default vals):

  :default-locale      ; Optional fallback locale to try when given
                       ; locales don't have the requested resource/s.

  :dict                ; Dictionary map of resources,
                       ; {<locale> {<k1> ... {<kn> <resource>}}}.
                       ; See also `tempura/example-dictionary`.

  :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?         ; Only reason you'd want this off is if
                       ; you're using :__load-resource imports and
                       ; and want dictionary to pick up changes.

  :cache-locales?      ; Client will usu. be dealing with a small
                       ; number of locales, the server often a
                       ; large number in the general case. `tr`
                       ; partials may want to enable cached locale
                       ; expansion (e.g. in the context of a
                       ; particular user's Ring request, etc.).

  :cache-resources?    ; For the very highest possible performance
                       ; when using a limited domain of locales +
                       ; resource ids.
sourceraw docstring

with-tr-optsclj/s≠macro

clj
(with-tr-opts opts & body)
cljs
(with-tr-opts &form &env opts & body)
source (clj)source (cljs)

with-tr-scopeclj/s≠macro

clj
(with-tr-scope scope & body)
cljs
(with-tr-scope &form &env scope & body)

(with-tr-scope :foo.bar (tr _ _ [:baz])) is equivalent to (tr _ _ [:foo.bar/baz])

`(with-tr-scope :foo.bar (tr _ _ [:baz]))` is equivalent to
`(tr _ _ [:foo.bar/baz])`
source (clj)source (cljs)raw docstring

wrap-ring-requestclj

(wrap-ring-request handler {:keys [tr-opts]})

Alpha, subject to change. Wraps Ring handler to add the following keys to requests:

:tempura/accept-langs ; e.g. ["en-ES" "en-US"], parsed from ; request's Accept-Language HTTP header.

:tempura/tr ; (partial tr tr-opts (:tr-locales ring-req accept-langs)), ; (fn ([resource-ids]) ([resource-ids args]))

Alpha, subject to change.
Wraps Ring handler to add the following keys to requests:

  :tempura/accept-langs ; e.g. ["en-ES" "en-US"], parsed from
                        ; request's Accept-Language HTTP header.

  :tempura/tr ; (partial tr tr-opts (:tr-locales ring-req accept-langs)),
              ; (fn ([resource-ids]) ([resource-ids args]))
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close