clj18n.ring.middleware documentation

Ring middleware for loading dictionaries and setting locales.

locale-from-domain

(locale-from-domain {:keys [server-name]})
Gets the locale from the request server-name, by looking for a two-character
language subdomain, avoiding capture of www and main domain.

locale-from-header

(locale-from-header {:keys [headers]})
Gets the locale from the request Accept-Language header.

locale-from-param

(locale-from-param {:keys [params]})
Gets the locale based on the :locale param.

locale-from-uri

(locale-from-uri {:keys [uri], :as req})
Gets the locale from the request uri, using the first part of the URI as the
locale.

wrap-i18n

(wrap-i18n app dict & args)
Calls both wrap-locale and wrap-translation with the given arguments.

wrap-locale

(wrap-locale app & {:keys [default locale-fns], :or {default :en, locale-fns [locale-from-header locale-from-param]}})
Sets request :locale to the first value returned by :locale-fns or to
:default. :locale-fns are functions that take the request as argument and
return a locale string or nil.

wrap-translation

(wrap-translation app dict)
Sets request :t to be a function of translations for dict and request
:locale.