dev / templates / app-cljs-live / client / src / __NAME__ / i18n.cljs
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
;; The app's i18n entry: binds the vendored runtime to THIS app's catalogs
;; and namespace and hydrates the static markup at load. Add a key-set test
;; (en == ro/hu) when black-box tests arrive — game1's test/i18n.test.mjs is
;; the shape. Require this before anything that renders text.
(ns __NAME__.i18n
  (:require [__NAME__.config :as config]
            [__NAME__.i18n.en :as en]
            [__NAME__.i18n.hu :as hu]
            [__NAME__.i18n.ro :as ro]
            [__NAME__.i18n.runtime :as rt]))

;; same slug the identity boot derives (__NAME__.id.boot/ns-of) — the lang
;; mirror lives beside the identity mirror under the app's namespace
(def ^:private ns*
  (-> config/APP-SALT
      (.toLowerCase)
      (.replace (js/RegExp. "[^a-z0-9]+" "g") "-")
      (.replace (js/RegExp. "^-+|-+$" "g") "")))

(defonce ^:private booted
  (do (rt/init-i18n {:ns ns*
                     :catalogs {"en" en/catalog "ro" ro/catalog "hu" hu/catalog}})
      (rt/hydrate-html js/document)
      true))

(def t rt/t)
(def tn rt/tn)

;; Untyped view for injecting into kits (social-kit's `t` option): unknown
;; keys come back as the key itself, which the kit treats as "use built-in".
;; The kits call it with plain JS vars objects — the runtime handles both.
(defn t-kit
  ([k] (rt/t k nil))
  ([k vars] (rt/t k vars)))

(def absorb-suite-lang rt/absorb-suite-lang)
(def fmt-date rt/fmt-date)
(def fmt-num rt/fmt-num)
(def fmt-time rt/fmt-time)
(def get-lang rt/get-lang)
(def hydrate-html rt/hydrate-html)
(def lang-picker-el rt/lang-picker-el)
(def on-lang-change rt/on-lang-change)
(def set-lang rt/set-lang)

static mirror of HEAD · about · clone: git clone https://git.ardegazu.ro/dev.git