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


*tr-scope*clj/s


_get-default-resource-compilerclj/s


default-tr-optsclj/s


example-dictionaryclj/s


get-default-resource-compilerclj/s

(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.

Implementation detail.
Good general-purpose resource compiler.
Supports output of text, and Hiccup forms with simple Markdown styles.
raw docstring

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`.
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`.
raw docstring

new-tr-fnclj/s

(new-tr-fn opts)

Returns a new translate ("tr") function, (fn tr [locales resource-ids ?resource-args]) -> translation.

When caching is enabled, cache is by default local to the returned tr fn.

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 true for Cljs.

:cache-locales? ; Cache locale processing? Improves performance, safe iff ; the returned tr fn will see a limited number of ; locales inputs (common example: calling ; tempura/new-tr-fn for each Ring request). ; ; Default is false for Clj and true for Cljs.

:cache-resources? ; Cache translation resource lookup? Improves performance ; but will consume memory for every combination of ; locale and resource id. Safe only if these are limited. ; ; Default is false.

:global-cache? ; When false, any caching is local to returned tr fn. ; When true, any caching is shared across all tr fns ; with :global-cache? enabled. ; ; Default is false.

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.

See GitHub README for more info & examples, Ref. https://github.com/ptaoussanis/tempura

Returns a new translate ("tr") function,
  (fn tr [locales resource-ids ?resource-args]) -> translation.

When caching is enabled, cache is by default local to the returned `tr` fn.

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 `true` for Cljs.

  :cache-locales?      ; Cache locale processing? Improves performance, safe iff
                       ; the returned `tr` fn will see a limited number of
                       ; `locales` inputs (common example: calling
                       ; `tempura/new-tr-fn` for each Ring request).
                       ;
                       ; Default is `false` for Clj and `true` for Cljs.

  :cache-resources?    ; Cache translation resource lookup? Improves performance
                       ; but will consume memory for *every* combination of
                       ; locale and resource id. Safe only if these are limited.
                       ;
                       ; Default is `false`.

  :global-cache?       ; When `false`, any caching is local to returned `tr` fn.
                       ; When `true`,  any caching is shared across all `tr` fns
                       ; with `:global-cache?` enabled.
                       ;
                       ; Default is `false`.

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`.

See GitHub README for more info & examples, Ref.
  https://github.com/ptaoussanis/tempura
raw 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.
raw docstring

trclj/s

(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.

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.
raw docstring

with-tr-optsclj/smacro

(with-tr-opts opts & body)

with-tr-scopeclj/smacro

(with-tr-scope 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])`
raw docstring

wrap-ring-requestclj

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

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

:tempura/accept-langs_ ; Possible delay with value parsed from Ring ; request's "Accept-Language" HTTP header. ; E.g. value: ["en-ES" "en-US"].

:tempura/tr ; (partial tempura/new-tr-fn tr-opts ; (or locales (:tempura/locales ring-req) accept-langs_)), ; => (fn [resource-ids ?resource-args]) -> translation

tr-opts will by default include {:cache-locales? true}.

When caching is enabled, cache is by default local to the tr fn created for each Ring request. If instead you want a global cache (shared across all Ring requests), include {:global-cache? true} in tr-opts.

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

  :tempura/accept-langs_ ; Possible delay with value parsed from Ring
                         ; request's "Accept-Language" HTTP header.
                         ; E.g. value: ["en-ES" "en-US"].

  :tempura/tr ; (partial tempura/new-tr-fn tr-opts
              ;   (or locales (:tempura/locales ring-req) accept-langs_)),
              ; => (fn [resource-ids ?resource-args]) -> translation

`tr-opts` will by default include {:cache-locales? true}.

When caching is enabled, cache is by default local to the `tr` fn
created for each Ring request. If instead you want a global cache
(shared across all Ring requests), include {:global-cache? true} in
`tr-opts`.
raw docstring

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

× close