amelinium.i18n
added in 1.0.0
I18N support for amelinium
lang
(lang req)
Tries to obtain a language from a request map (:language/id
key). Falls back to a default language (:language/default
) if the first one is nil
. Returns a keyword.
missing-key
(missing-key f locale k)
Returns a warning string for a missing key (defined under a special key :amelinium/missing-key
) if the dynamic variable *handle-missing-keys*
is set to a truthy value. Otherwise it returns nil
.
no-default
macro
(no-default & body)
Sets *handle-missing-keys*
dynamic variable to false
, causing translation functions to return nil
when translation key is not found instead of a warning string. Also, when used with translation-fn
, translator
or translator-sub
causes generated function to always behave that way.
tr
(tr req key)
(tr req key x)
(tr req key x y)
(tr req key x y & more)
Returns a translation string for the given locale (obtained from a request map) and the keyword key
using a translation function (obtained from a request map or a Match
object). Any optional arguments are passed as they are.
If *handle-missing-keys*
dynamic variable is set to false
or nil
(which can be set using no-default
macro) then the function will return nil
when a key is missing instead of a warning string.
If a translation function tr
was generated (using translation-fn
, translator
or translator-sub
) with *handle-missing-keys*
dynamic variable set to false
or nil
then it will always return nil
when a key is missing, regardless of current value of *handle-missing-keys*
in the calling context.
tr-sub
(tr-sub req key-ns key-name)
(tr-sub req key-ns key-name x)
(tr-sub req key-ns key-name x y)
(tr-sub req key-ns key-name x y & more)
Returns a translation string for the given locale (obtained from a request map), the namespace name key-ns
and the key name key-name
. Useful to translate nested keys which are translated to fully-qualified keywords. The translation function will be obtained by calling translator
on req
(which may be a request map or a Match
object). Any additional arguments are passed as they are.
If *handle-missing-keys*
dynamic variable is set to false
or nil
(which can be set using no-default
macro) then the function will return nil
when a key is missing instead of a warning string.
If a translation function tr
was generated (using translation-fn
, translator
or translator-sub
) with *handle-missing-keys*
dynamic variable set to false
or nil
then it will always return nil
when a key is missing, regardless of current value of *handle-missing-keys*
in the calling context.
translate
(translate req locale key)
(translate req locale key x)
(translate req locale key x y)
(translate req locale key x y & more)
Returns a translation string for the given locale
(language ID) and the keyword key
using a translation function obtained from the given request map (req
) by calling translator
function on it. Any optional arguments are passed as they are.
If *handle-missing-keys*
dynamic variable is set to false
or nil
(which can be set using no-default
macro) then the function will return nil
when a key is missing instead of a warning string.
If a translation function tr
was generated (using translation-fn
, translator
or translator-sub
) with *handle-missing-keys*
dynamic variable set to false
or nil
then it will always return nil
when a key is missing, regardless of current value of *handle-missing-keys*
in the calling context.
translate-sub
(translate-sub req locale key-ns key-name)
(translate-sub req locale key-ns key-name x)
(translate-sub req locale key-ns key-name x y)
(translate-sub req locale key-ns key-name x y & more)
Returns a translation string for the given locale
(language ID), the namespace name ns-name
and the key name key-name
. Useful to translate nested keys which are translated to fully-qualified keywords. The translation function will be obtained by calling translator
on req
(which may be a request map or a Match
object). Any additional arguments are passed as they are.
If *handle-missing-keys*
dynamic variable is set to false
or nil
(which can be set using no-default
macro) then the function will return nil
when a key is missing instead of a warning string.
If a translation function tr
was generated (using translation-fn
, translator
or translator-sub
) with *handle-missing-keys*
dynamic variable set to false
or nil
then it will always return nil
when a key is missing, regardless of current value of *handle-missing-keys*
in the calling context.
translate-sub-with
(translate-sub-with tf locale key-ns key-name)
(translate-sub-with tf locale key-ns key-name x)
(translate-sub-with tf locale key-ns key-name x y)
(translate-sub-with tf locale key-ns key-name x y & more)
Returns a translation string for the given locale
(language ID), the namespace name ns-name
and the key name key-name
, using the given translation function tf
. Useful to translate nested keys which are translated to fully-qualified keywords. Any additional arguments are passed as they are.
If *handle-missing-keys*
dynamic variable is set to false
or nil
(which can be set using no-default
macro) then the function will return nil
when a key is missing instead of a warning string.
If a translation function tr
was generated (using translation-fn
, translator
or translator-sub
) with *handle-missing-keys*
dynamic variable set to false
or nil
then it will always return nil
when a key is missing, regardless of current value of *handle-missing-keys*
in the calling context.
translate-with
(translate-with tf locale key)
(translate-with tf locale key x)
(translate-with tf locale key x y)
(translate-with tf locale key x y & more)
Returns a translation string for the given locale
(language ID) and the keyword key
using a translation function tf
. Any optional arguments are passed as they are.
If *handle-missing-keys*
dynamic variable is set to false
or nil
(which can be set using no-default
macro) then the function will return nil
when a key is missing instead of a warning string.
If a translation function tr
was generated (using translation-fn
, translator
or translator-sub
) with *handle-missing-keys*
dynamic variable set to false
or nil
then it will always return nil
when a key is missing, regardless of current value of *handle-missing-keys*
in the calling context.
translation-fn
(translation-fn req-or-match)
Tries to obtain translation function from a route data in a request map or a Match
object and if that fails from a request map itself. Falls back to a global variable amelinium.i18n/translations
.
If *handle-missing-keys*
dynamic variable is set to false
or nil
then the generated translation function will always generate nil
when a key is missing, ignoring dynamic binding.
translator
(translator req-or-match)
(translator req-or-match locale)
Tries to obtain translation function from a route data in a request map or a Match
object and if that fails from a request map itself. Falls back to a global variable amelinium.i18n/translations
.
When locale
is given it will generate a translation function with predefined translator and locale. If it’s not given, it will use language obtained from the context map req
.
If *handle-missing-keys*
dynamic variable is set to false
or nil
then the generated translation function will always generate nil
when a key is missing, ignoring dynamic binding.
translator-sub
(translator-sub req-or-match)
(translator-sub req-or-match locale)
Tries to obtain translation function from a route data in a request map or a Match
object and if that fails from a request map itself. Falls back to a global variable amelinium.i18n/translations
. The translation function will accept key-ns
and key-name
arguments which will be used to build a keyword with the given namespace and name. This keyword will be used as a translation key.
When locale
is given it will generate a translation function with predefined translator and locale. If it’s not given, it will use language obtained from the context map req
.
If *handle-missing-keys*
dynamic variable is set to false
or nil
then the generated translation function will always generate nil
when a key is missing, ignoring dynamic binding.