amelinium.http.middleware.language

added in 1.0.0

amelinium service, language middleware.

accept-picker

body-phone-picker

body-phone-picker-str

body-picker

config

(config req)(config req config)

Returns language settings obtained from a request map.

default-fallback-language

default-lang-id

(default-lang-id req)(default-lang-id _ config)

Returns an ID (a keyword) of a default language set in config (under the :default key) or a value of the default-fallback-language variable (:en).

default-lang-param

default-picker

default-picker-chain

force

(force req language)

Forces different language in a request map by setting :language/id and :language/str.

form-param-phone-picker

form-param-phone-picker-str

form-params-picker

form-params-picker-str

from-accept

(from-accept req)(from-accept req config)(from-accept req _ _ supp)

from-body

(from-body req)(from-body req config)(from-body req _ lang-param supp)

from-default

(from-default req)(from-default req config)(from-default _ _ default)

from-form-params

(from-form-params req)(from-form-params req config)(from-form-params req _ lang-param supp)

from-path

(from-path req)(from-path req config)(from-path req lang-param supp)

get-in-req

(get-in-req req supported k)(get-in-req req supported k1 k2)(get-in-req req supported k1 k2 k3)(get-in-req req supported k1 k2 k3 & kpath)

Reads a language from the given request map by getting a value specified by a sequence of keys, converting the result to a keyword and checking against a set of supported languages.

init-picker-chain

(init-picker-chain config pickers)

init-pickers

(init-pickers config)

param

(param req)(param _ config)

Returns a value associated with :param key in settings obtained from a request map or a config. If it does not exist or has falsy value, default-lang-param is returned.

path-picker

pick

(pick req)(pick req pickers)(pick req picker-id)(pick req pickers picker-id)

Picks the right language using a chain of picking functions identified by a keyword. In its unary variant it obtains language picker chains configuration from a request map (under :language/pickers key) and looks for the picker chain identified by the :default key. When it’s not nil, it is used.

In its binary variant it takes a request map and pickers configuration given as a map OR a request map and an ID of a picker given as a keyword. When a map is given, the picker chain associated with the :default key will be used. When a picker ID is given the chain will be selected from picker chains obtained from the req under the key :language/pickers. Next, the picker chain will be run with a request map as its argument and the result will be then returned.

In its ternary variant the given pickers map will be used to look for a chain under the given picker-id. This chain will be run with a request map as its argument to get the language.

If the value returned by a language picker chain will be nil or false then the default language will be returned (if configured).

pick-without-fallback

(pick-without-fallback req)(pick-without-fallback req pickers-or-picker-id)(pick-without-fallback req pickers picker-id)

The same as pick but returns nil instead of a default language when pickers cannot get one.

pickers

(pickers req)

Returns configured pickers map obtained from a request.

prep-language

(prep-language config)

prep-supported

(prep-supported v)

process-picker

(process-picker config p)

Prepares a single picker. If it is a map, :compile key should be associated with a function which will return a language-picking function. Symbol may be given and it will be resolved. The compiling function should take a single argument which is a middleware configuration. All keys of the map except :handler and :compile will be passed to it.

If :handler is specified in a map, it should be a function or a symbol which resolves to a function.

If the p is not a map, it should be a function.

A function returned by the compiling function, given as :handler, or simply assigned should take one argument, a request map, and return a language identifier as a keyword.

When a language-picking function is created on a basis of a map (specified by :handler or :compile) then it has the responsibility of transforming its result to a keyword and checking if the chosen language identifier belongs to a supported languages expressed in a configuration as a set under the :supported key. Note that picker compiling function will receive configuration under the config key and should generate a function which takes a single argument (request map) whereas handler should take two arguments, the first being a configuration.

When a language-picking function is not a map but a function (or a symbolic, resolvable identifier of a function) then it will be wrapped in another function and its result will be converted to a keyword and tested against existence in the aforementioned set of supported languages.

query-params-picker

query-params-picker-str

re-lang

req-picker

supported

(supported req)(supported _ config)

Returns a value associated with :supported key in settings obtained from a request map or a config.

wrap-language

(wrap-language k config)

Language wrapping middleware.