chat / client / src / sueta / testlib.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
;; Test-only entry: pulls in every namespace whose vars shadow-cljs.edn's
;; :testlib :exports name, plus the i18n catalog accessors the node --test suite
;; in test/*.test.mjs drives. Never part of the :app build.
(ns sueta.testlib
  (:require ;; the shared rooms core, from ardegazu-rooms-kit's sources on the
   ;; classpath (client/deps.edn) — no longer vendored here
   [ardegazu.rooms.js :as j]
   [ardegazu.rooms.lib.access]
   [ardegazu.rooms.lib.crypto]
   [ardegazu.rooms.lib.descriptor]
   [ardegazu.rooms.lib.encryption]
   [ardegazu.rooms.lib.log]
   [ardegazu.rooms.lib.net]
   [ardegazu.rooms.lib.orbit-identity]
   [ardegazu.rooms.lib.turn]
   ;; chat's own
   [sueta.app.call]
   [sueta.app.chat]
   [sueta.app.history]
   [sueta.app.migrate]
   [sueta.app.migrate-storage]
   [sueta.app.rooms]
   [sueta.app.trust]
   [sueta.config]
   [sueta.i18n :as i18n]
   [sueta.i18n.en :as en]
   [sueta.i18n.hu :as hu]
   [sueta.i18n.ro :as ro]
   [sueta.lib.mailbox]
   [sueta.lib.media]
   [sueta.lib.selftest]
   [sueta.stores]))

(def ^:private catalogs
  {"en" en/catalog "ro" ro/catalog "hu" hu/catalog})

(defn catalog-keys
  "Sorted js array of the message keys of catalog `lang`."
  [lang]
  (.sort (to-array (keys (get catalogs lang)))))

(defn catalog-msg
  "The message under `k`: a string, or a js array of the plural-variant category
   names it defines (sorted)."
  [lang k]
  (let [msg (get-in catalogs [lang k])]
    (if (string? msg)
      msg
      (when (some? msg) (.sort (to-array (keys msg)))))))

(defn catalog-raw
  "The FULL message under `k`: a string, or a plain JS object of its plural
   variants (key ORDER is not significant — catalogs are CLJS maps, and the
   snapshot test compares per key)."
  [lang k]
  (let [msg (get-in catalogs [lang k])]
    (if (string? msg)
      msg
      (when (some? msg)
        (let [o (j/ordered)]
          (doseq [[variant text] msg] (unchecked-set o variant text))
          o)))))

(defn t
  ([k] (i18n/t k nil))
  ([k vars] (i18n/t k vars)))

(defn tn
  ([k n] (i18n/tn k n nil))
  ([k n vars] (i18n/tn k n vars)))

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