parent
1a6851efa0
commit
2e7f4212c1
|
@ -1,4 +1,5 @@
|
||||||
(ns mocks.js-dependencies
|
(ns mocks.js-dependencies
|
||||||
|
(:require-macros [status-im.utils.slurp :refer [slurp]])
|
||||||
(:require [status-im.default-fleet :refer (default-fleets)]))
|
(:require [status-im.default-fleet :refer (default-fleets)]))
|
||||||
|
|
||||||
(def action-button #js {:default #js {:Item #js {}}})
|
(def action-button #js {:default #js {:Item #js {}}})
|
||||||
|
@ -206,4 +207,20 @@
|
||||||
"react-native-image-resizer" image-resizer
|
"react-native-image-resizer" image-resizer
|
||||||
"react-native-haptic-feedback" react-native-haptic-feedback
|
"react-native-haptic-feedback" react-native-haptic-feedback
|
||||||
"./fleets.js" default-fleets
|
"./fleets.js" default-fleets
|
||||||
|
"../translations/ar.json" (js/JSON.parse (slurp "./translations/ar.json"))
|
||||||
|
"../translations/de.json" (js/JSON.parse (slurp "./translations/de.json"))
|
||||||
|
"../translations/en.json" (js/JSON.parse (slurp "./translations/en.json"))
|
||||||
|
"../translations/es.json" (js/JSON.parse (slurp "./translations/es.json"))
|
||||||
|
"../translations/es_419.json" (js/JSON.parse (slurp "./translations/es_419.json"))
|
||||||
|
"../translations/fil.json" (js/JSON.parse (slurp "./translations/fil.json"))
|
||||||
|
"../translations/fr.json" (js/JSON.parse (slurp "./translations/fr.json"))
|
||||||
|
"../translations/id.json" (js/JSON.parse (slurp "./translations/id.json"))
|
||||||
|
"../translations/it.json" (js/JSON.parse (slurp "./translations/it.json"))
|
||||||
|
"../translations/ko.json" (js/JSON.parse (slurp "./translations/ko.json"))
|
||||||
|
"../translations/pt_br.json" (js/JSON.parse (slurp "./translations/pt_br.json"))
|
||||||
|
"../translations/ru.json" (js/JSON.parse (slurp "./translations/ru.json"))
|
||||||
|
"../translations/tr.json" (js/JSON.parse (slurp "./translations/tr.json"))
|
||||||
|
"../translations/zh.json" (js/JSON.parse (slurp "./translations/zh.json"))
|
||||||
|
"../translations/zh_hant.json" (js/JSON.parse (slurp "./translations/zh_hant.json"))
|
||||||
|
"../translations/zh_TW.json" (js/JSON.parse (slurp "./translations/zh_TW.json"))
|
||||||
nil))
|
nil))
|
||||||
|
|
|
@ -1,21 +0,0 @@
|
||||||
(ns status-im.i18n
|
|
||||||
(:require [clojure.string :as string]))
|
|
||||||
|
|
||||||
(defn read-file [f]
|
|
||||||
(when (.isFile f)
|
|
||||||
(let [locale (-> f
|
|
||||||
.getName
|
|
||||||
(string/split #"\.")
|
|
||||||
first)
|
|
||||||
content (slurp f)]
|
|
||||||
[(keyword locale) content])))
|
|
||||||
|
|
||||||
(defn read-translations []
|
|
||||||
(->>
|
|
||||||
(java.io.File. "translations")
|
|
||||||
file-seq
|
|
||||||
(keep read-file)
|
|
||||||
vec))
|
|
||||||
|
|
||||||
(defmacro translations [languages]
|
|
||||||
(select-keys (into {} (read-translations)) languages))
|
|
|
@ -1,21 +1,66 @@
|
||||||
(ns status-im.i18n-resources
|
(ns status-im.i18n-resources
|
||||||
(:require-macros [status-im.i18n :as i18n])
|
(:require [clojure.string :as string]
|
||||||
(:require [status-im.utils.types :as types]
|
["i18n-js" :as i18n-js]
|
||||||
[clojure.string :as string]
|
|
||||||
["react-native-languages" :default react-native-languages]))
|
["react-native-languages" :default react-native-languages]))
|
||||||
|
|
||||||
(def default-device-language
|
(def default-device-language
|
||||||
(keyword (.-language react-native-languages)))
|
(keyword (.-language react-native-languages)))
|
||||||
|
|
||||||
|
;; Update js_dependencies.cljs
|
||||||
|
(def languages [:ar :de :en :es :es_419 :fil :fr :id :in :it :ko :pt_BR :ru :tr :zh :zh_Hant :zh_TW])
|
||||||
|
|
||||||
|
(defonce loaded-languages
|
||||||
|
(atom
|
||||||
|
(conj #{:en} default-device-language)))
|
||||||
|
|
||||||
|
(def translations
|
||||||
|
{:ar (js/require "../translations/ar.json")
|
||||||
|
:de (js/require "../translations/de.json")
|
||||||
|
:en (js/require "../translations/en.json")
|
||||||
|
:es (js/require "../translations/es.json")
|
||||||
|
:es_419 (js/require "../translations/es_419.json")
|
||||||
|
:fil (js/require "../translations/fil.json")
|
||||||
|
:fr (js/require "../translations/fr.json")
|
||||||
|
:id (js/require "../translations/id.json")
|
||||||
|
:in (js/require "../translations/id.json")
|
||||||
|
:it (js/require "../translations/it.json")
|
||||||
|
:ko (js/require "../translations/ko.json")
|
||||||
|
:pt_BR (js/require "../translations/pt_br.json")
|
||||||
|
:ru (js/require "../translations/ru.json")
|
||||||
|
:tr (js/require "../translations/tr.json")
|
||||||
|
:zh (js/require "../translations/zh.json")
|
||||||
|
:zh_Hant (js/require "../translations/zh_hant.json")
|
||||||
|
:zh_TW (js/require "../translations/zh_TW.json")})
|
||||||
|
|
||||||
|
(defn valid-language [lang]
|
||||||
|
(if (contains? translations lang)
|
||||||
|
(keyword lang)
|
||||||
|
(let [parts (string/split (name lang) #"[\-\_]")
|
||||||
|
short-lang (keyword (str (first parts) "_" (second parts)))
|
||||||
|
shortest-lang (keyword (first parts))]
|
||||||
|
(if (and (> (count parts) 2) (contains? translations short-lang))
|
||||||
|
short-lang
|
||||||
|
(when (contains? translations shortest-lang)
|
||||||
|
shortest-lang)))))
|
||||||
|
|
||||||
|
(defn require-translation [lang-key]
|
||||||
|
(when-let [lang (valid-language (keyword lang-key))]
|
||||||
|
(get translations lang)))
|
||||||
|
|
||||||
;; translations
|
;; translations
|
||||||
(def translations-by-locale
|
(def translations-by-locale
|
||||||
(->> (i18n/translations [:ar :de :en :es :es_419 :fil :fr :id :in :it :ko :pt_BR :ru :tr :zh :zh_Hant :zh_TW])
|
(cond->
|
||||||
(map (fn [[k t]]
|
{:en (require-translation :en)
|
||||||
(let [k' (-> (name k)
|
(not= :en default-device-language)
|
||||||
(string/replace "_" "-")
|
(assoc default-device-language
|
||||||
keyword)]
|
(require-translation (-> (name default-device-language)
|
||||||
[k' (types/json->clj t)])))
|
(string/replace "-" "_")
|
||||||
(into {})))
|
keyword)))}))
|
||||||
|
|
||||||
;; API compatibility
|
(defn load-language [lang]
|
||||||
(defn load-language [_])
|
(when-let [lang-key (valid-language (keyword lang))]
|
||||||
|
(when-not (contains? @loaded-languages lang-key)
|
||||||
|
(aset (.-translations i18n-js)
|
||||||
|
lang
|
||||||
|
(require-translation lang-key))
|
||||||
|
(swap! loaded-languages conj lang-key))))
|
||||||
|
|
|
@ -7,14 +7,15 @@
|
||||||
[clojure.string :as string]))
|
[clojure.string :as string]))
|
||||||
|
|
||||||
;; english as source of truth
|
;; english as source of truth
|
||||||
(def labels (set (keys (:en i18n-resources/translations-by-locale))))
|
(def labels (set (keys (js->clj (:en i18n-resources/translations-by-locale)
|
||||||
|
:keywordize-keys true))))
|
||||||
|
|
||||||
(spec/def ::label labels)
|
(spec/def ::label labels)
|
||||||
(spec/def ::labels (spec/coll-of ::label :kind set? :into #{}))
|
(spec/def ::labels (spec/coll-of ::label :kind set? :into #{}))
|
||||||
|
|
||||||
(defn labels-for-all-locales []
|
(defn labels-for-all-locales []
|
||||||
(->> i18n-resources/translations-by-locale
|
(->> i18n-resources/translations-by-locale
|
||||||
(mapcat #(-> % val keys))
|
(mapcat #(-> % val (js->clj :keywordize-keys true) keys))
|
||||||
set))
|
set))
|
||||||
|
|
||||||
;; checkpoints
|
;; checkpoints
|
||||||
|
@ -1029,7 +1030,7 @@
|
||||||
(spec/def ::locales (spec/coll-of ::locale :kind set? :into #{}))
|
(spec/def ::locales (spec/coll-of ::locale :kind set? :into #{}))
|
||||||
|
|
||||||
(defn locale->labels [locale]
|
(defn locale->labels [locale]
|
||||||
(-> i18n-resources/translations-by-locale (get locale) keys set))
|
(-> i18n-resources/translations-by-locale (get locale) (js->clj :keywordize-keys true) keys set))
|
||||||
|
|
||||||
(defn locale->checkpoint [locale]
|
(defn locale->checkpoint [locale]
|
||||||
(let [locale-labels (locale->labels locale)
|
(let [locale-labels (locale->labels locale)
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
[status-im.utils.config :as config]
|
[status-im.utils.config :as config]
|
||||||
[status-im.utils.fx :as fx]
|
[status-im.utils.fx :as fx]
|
||||||
[status-im.utils.platform :as utils.platform]
|
[status-im.utils.platform :as utils.platform]
|
||||||
[status-im.utils.types :as types])
|
[status-im.utils.types :as types]))
|
||||||
(:require-macros [status-im.utils.slurp :refer [slurp]]))
|
|
||||||
|
|
||||||
(defn- add-custom-bootnodes [config network all-bootnodes]
|
(defn- add-custom-bootnodes [config network all-bootnodes]
|
||||||
(let [bootnodes (as-> all-bootnodes $
|
(let [bootnodes (as-> all-bootnodes $
|
||||||
|
@ -70,10 +69,8 @@
|
||||||
[limit nodes]
|
[limit nodes]
|
||||||
(take limit (shuffle nodes)))
|
(take limit (shuffle nodes)))
|
||||||
|
|
||||||
(def default-fleets (slurp "resources/config/fleets.json"))
|
|
||||||
|
|
||||||
(defn fleets [{:keys [custom-fleets]}]
|
(defn fleets [{:keys [custom-fleets]}]
|
||||||
(as-> [default-fleets] $
|
(as-> [(js/require "./fleets.js")] $
|
||||||
(mapv #(:fleets (types/json->clj %)) $)
|
(mapv #(:fleets (types/json->clj %)) $)
|
||||||
(conj $ custom-fleets)
|
(conj $ custom-fleets)
|
||||||
(reduce merge $)))
|
(reduce merge $)))
|
||||||
|
|
Loading…
Reference in New Issue