Line data Source code
1 4 : (ns matchscore.telegram.localization
2 : (:require
3 : [matchscore.domain.template.repository.postgres :as template-postgres-repo]
4 : [matchscore.i18n :as i18n]
5 : [matchscore.telegram.formatting :as formatting]))
6 :
7 :
8 4 : (defn value-at
9 : [m k]
10 33 : (or (get m k) (get m (name k))))
11 :
12 :
13 4 : (defn configured-language
14 : [m]
15 16 : (value-at m :language))
16 :
17 :
18 4 : (defn message-locale
19 : [repos event]
20 16 : (let [event-language (configured-language event)
21 30 : template-language (when-let [template-id (:template-id event)]
22 16 : (some->
23 4 : (template-postgres-repo/find-by-id
24 6 : (:template-postgres-repo repos)
25 2 : template-id
26 2 : {})
27 2 : configured-language))]
28 8 : (formatting/normalize-locale
29 30 : (or
30 39 : (when (and event-language (not= "en" event-language)) event-language)
31 4 : template-language
32 : event-language))))
33 :
34 :
35 4 : (defn resource-locale
36 : [resource]
37 10 : (formatting/normalize-locale (configured-language resource)))
38 :
39 :
40 4 : (defn t
41 : [locale k & args]
42 32 : (apply i18n/translate (formatting/normalize-locale locale) k args))
|