2019-06-01 06:47:37 +00:00
|
|
|
(ns status-im.i18n-resources
|
2020-01-28 16:47:38 +00:00
|
|
|
(:require [status-im.react-native.js-dependencies :as rn-dependencies]
|
|
|
|
[clojure.string :as string]))
|
2019-06-01 06:47:37 +00:00
|
|
|
|
|
|
|
(def default-device-language
|
|
|
|
(keyword (.-language rn-dependencies/react-native-languages)))
|
|
|
|
|
2020-03-31 15:06:48 +00:00
|
|
|
(def languages [:ar :en :es :es_419 :fil :fr :id :in :it :ko :zh :zh_Hant :zh_TW])
|
2019-06-01 06:47:37 +00:00
|
|
|
|
|
|
|
(defonce loaded-languages
|
|
|
|
(atom
|
|
|
|
(conj #{:en} default-device-language)))
|
|
|
|
|
2019-10-24 17:05:03 +00:00
|
|
|
(def prod-translations
|
2020-03-31 15:06:48 +00:00
|
|
|
{
|
2019-10-24 17:05:03 +00:00
|
|
|
:ar (js/require "status-modules/translations/ar.json")
|
|
|
|
:en (js/require "status-modules/translations/en.json")
|
|
|
|
:es (js/require "status-modules/translations/es.json")
|
|
|
|
:es_419 (js/require "status-modules/translations/es_419.json")
|
2020-03-23 14:33:02 +00:00
|
|
|
:fil (js/require "status-modules/translations/fil.json")
|
2019-10-24 17:05:03 +00:00
|
|
|
:fr (js/require "status-modules/translations/fr.json")
|
|
|
|
:id (js/require "status-modules/translations/id.json")
|
2020-03-28 15:49:33 +00:00
|
|
|
:in (js/require "status-modules/translations/id.json")
|
2019-10-24 17:05:03 +00:00
|
|
|
:it (js/require "status-modules/translations/it.json")
|
|
|
|
:ko (js/require "status-modules/translations/ko.json")
|
2020-03-28 15:49:33 +00:00
|
|
|
:zh (js/require "status-modules/translations/zh.json")
|
|
|
|
:zh_Hant (js/require "status-modules/translations/zh_TW.json")
|
|
|
|
:zh_TW (js/require "status-modules/translations/zh_TW.json")})
|
2019-06-01 06:47:37 +00:00
|
|
|
|
|
|
|
(defn valid-language [lang]
|
|
|
|
(if (contains? prod-translations lang)
|
|
|
|
lang
|
2020-03-28 15:49:33 +00:00
|
|
|
(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? prod-translations short-lang))
|
|
|
|
short-lang
|
|
|
|
(when (contains? prod-translations shortest-lang)
|
|
|
|
shortest-lang)))))
|
2019-06-01 06:47:37 +00:00
|
|
|
|
|
|
|
(defn require-translation [lang-key]
|
|
|
|
(when-let [lang (valid-language lang-key)]
|
2019-08-26 12:57:26 +00:00
|
|
|
(get prod-translations lang)))
|
2019-06-01 06:47:37 +00:00
|
|
|
|
|
|
|
;; translations
|
|
|
|
(def translations-by-locale
|
|
|
|
(cond->
|
|
|
|
{:en (require-translation :en)}
|
|
|
|
(not= :en default-device-language)
|
|
|
|
(assoc default-device-language
|
2020-01-28 16:47:38 +00:00
|
|
|
(require-translation (-> (name default-device-language)
|
|
|
|
(string/replace "-" "_")
|
|
|
|
keyword)))))
|
2019-06-01 06:47:37 +00:00
|
|
|
|
|
|
|
(defn load-language [lang]
|
|
|
|
(let [lang-key (valid-language (keyword lang))]
|
|
|
|
(when-not (contains? @loaded-languages lang-key)
|
|
|
|
(aset (.-translations rn-dependencies/i18n)
|
|
|
|
lang
|
|
|
|
(require-translation lang-key))
|
|
|
|
(swap! loaded-languages conj lang-key))))
|