-
Notifications
You must be signed in to change notification settings - Fork 984
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Remove usage of inline require"
This reverts commit 5f7c795
- Loading branch information
1 parent
1a6851e
commit 2e7f421
Showing
5 changed files
with
81 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,66 @@ | ||
(ns status-im.i18n-resources | ||
(:require-macros [status-im.i18n :as i18n]) | ||
(:require [status-im.utils.types :as types] | ||
[clojure.string :as string] | ||
(:require [clojure.string :as string] | ||
["i18n-js" :as i18n-js] | ||
["react-native-languages" :default react-native-languages])) | ||
|
||
(def default-device-language | ||
(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 | ||
(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]) | ||
(map (fn [[k t]] | ||
(let [k' (-> (name k) | ||
(string/replace "_" "-") | ||
keyword)] | ||
[k' (types/json->clj t)]))) | ||
(into {}))) | ||
|
||
;; API compatibility | ||
(defn load-language [_]) | ||
(cond-> | ||
{:en (require-translation :en) | ||
(not= :en default-device-language) | ||
(assoc default-device-language | ||
(require-translation (-> (name default-device-language) | ||
(string/replace "-" "_") | ||
keyword)))})) | ||
|
||
(defn load-language [lang] | ||
(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)))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters