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-23 14:33:02 +00:00
|
|
|
(def languages [:af :ar :bel :cs :da :de :de_ch :el :en :es :es_419 :es_ar :es_mx :fa :fi :fil :fr :fr_ch :fy :he :hi :hu :id :it_ch :ja :ko :la :lt :lv :ms :nb :ne :nl :pl :pt_br :pt_pt :ro :ru :sl :sr_rs_cyrl :sr_rs :latn :sv :sw :th :tr :uk :ur :vi :zh])
|
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
|
|
|
|
{:af (js/require "status-modules/translations/af.json")
|
|
|
|
:ar (js/require "status-modules/translations/ar.json")
|
|
|
|
:bel (js/require "status-modules/translations/bel.json")
|
|
|
|
:cs (js/require "status-modules/translations/cs.json")
|
|
|
|
:da (js/require "status-modules/translations/da.json")
|
|
|
|
:de (js/require "status-modules/translations/de.json")
|
|
|
|
:de_ch (js/require "status-modules/translations/de_ch.json")
|
|
|
|
:el (js/require "status-modules/translations/el.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")
|
|
|
|
:es_ar (js/require "status-modules/translations/es_ar.json")
|
|
|
|
:es_mx (js/require "status-modules/translations/es_mx.json")
|
|
|
|
:fa (js/require "status-modules/translations/fa.json")
|
|
|
|
:fi (js/require "status-modules/translations/fi.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")
|
|
|
|
:fr_ch (js/require "status-modules/translations/fr_ch.json")
|
|
|
|
:fy (js/require "status-modules/translations/fy.json")
|
|
|
|
:he (js/require "status-modules/translations/he.json")
|
|
|
|
:hi (js/require "status-modules/translations/hi.json")
|
|
|
|
:hu (js/require "status-modules/translations/hu.json")
|
|
|
|
:id (js/require "status-modules/translations/id.json")
|
|
|
|
:it (js/require "status-modules/translations/it.json")
|
|
|
|
:it_ch (js/require "status-modules/translations/it_ch.json")
|
|
|
|
:ja (js/require "status-modules/translations/ja.json")
|
|
|
|
:ko (js/require "status-modules/translations/ko.json")
|
|
|
|
:la (js/require "status-modules/translations/la.json")
|
|
|
|
:lt (js/require "status-modules/translations/lt.json")
|
|
|
|
:lv (js/require "status-modules/translations/lv.json")
|
|
|
|
:ms (js/require "status-modules/translations/ms.json")
|
|
|
|
:nb (js/require "status-modules/translations/nb.json")
|
|
|
|
:ne (js/require "status-modules/translations/ne.json")
|
|
|
|
:nl (js/require "status-modules/translations/nl.json")
|
|
|
|
:pl (js/require "status-modules/translations/pl.json")
|
|
|
|
:pt_br (js/require "status-modules/translations/pt_br.json")
|
|
|
|
:pt_pt (js/require "status-modules/translations/pt_pt.json")
|
|
|
|
:ro (js/require "status-modules/translations/ro.json")
|
|
|
|
:ru (js/require "status-modules/translations/ru.json")
|
|
|
|
:sl (js/require "status-modules/translations/sl.json")
|
|
|
|
:sr_rs_cyrl (js/require "status-modules/translations/sr_rs_cyrl.json")
|
|
|
|
:sr_rs_latn (js/require "status-modules/translations/sr_rs_latn.json")
|
|
|
|
:sv (js/require "status-modules/translations/sv.json")
|
|
|
|
:sw (js/require "status-modules/translations/sw.json")
|
|
|
|
:th (js/require "status-modules/translations/th.json")
|
|
|
|
:tr (js/require "status-modules/translations/tr.json")
|
|
|
|
:uk (js/require "status-modules/translations/uk.json")
|
|
|
|
:ur (js/require "status-modules/translations/ur.json")
|
|
|
|
:vi (js/require "status-modules/translations/vi.json")
|
2019-11-27 14:39:49 +00:00
|
|
|
:zh (js/require "status-modules/translations/zh.json")})
|
2019-06-01 06:47:37 +00:00
|
|
|
|
|
|
|
(defn valid-language [lang]
|
|
|
|
(if (contains? prod-translations lang)
|
|
|
|
lang
|
2020-03-26 10:40:00 +00:00
|
|
|
(let [short-lang (keyword (first (string/split (name lang) #"_")))]
|
2019-06-01 06:47:37 +00:00
|
|
|
(when (contains? prod-translations short-lang)
|
|
|
|
short-lang))))
|
|
|
|
|
|
|
|
(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))))
|