cleanup and i18n revert (#14694)

This commit is contained in:
flexsurfer 2023-01-03 19:19:21 +01:00 committed by GitHub
parent 3fa6112669
commit 228c596a9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 106 additions and 122 deletions

View File

@ -1,78 +1,14 @@
(ns i18n.i18n (ns i18n.i18n
(:require ["i18n-js" :as i18n] (:require ["i18n-js" :as i18n]
[clojure.string :as string] [clojure.string :as string]
[status-im.goog.i18n :as goog.i18n] [status-im.goog.i18n :as goog.i18n]))
[react-native.languages :as react-native-languages]))
(def default-device-language (react-native-languages/get-lang-keyword)) (defn setup
[default-device-language translations-by-locale]
(def languages
#{:ar :bn :de :el :en :es :es_419 :es_AR :fil :fr :hi :id :in :it :ja :ko :ms :nl :pl :pt :pt_BR :ru
:tr :vi :zh :zh_Hant :zh_TW})
(defn valid-language
[lang]
(if (contains? languages 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? languages short-lang))
short-lang
(when (contains? languages shortest-lang)
shortest-lang)))))
(defn require-translation
[lang-key]
(when-let [lang (valid-language (keyword lang-key))]
(case lang
:ar (js/require "../translations/ar.json")
:bn (js/require "../translations/bn.json")
:de (js/require "../translations/de.json")
:el (js/require "../translations/el.json")
:en (js/require "../translations/en.json")
:es (js/require "../translations/es.json")
:es_419 (js/require "../translations/es_419.json")
:es_AR (js/require "../translations/es_AR.json")
:fil (js/require "../translations/fil.json")
:fr (js/require "../translations/fr.json")
:hi (js/require "../translations/hi.json")
:id (js/require "../translations/id.json")
:in (js/require "../translations/id.json")
:it (js/require "../translations/it.json")
:ja (js/require "../translations/ja.json")
:ko (js/require "../translations/ko.json")
:ms (js/require "../translations/ms.json")
:nl (js/require "../translations/nl.json")
:pl (js/require "../translations/pl.json")
:pt (js/require "../translations/pt.json")
:pt_BR (js/require "../translations/pt_BR.json")
:ru (js/require "../translations/ru.json")
:tr (js/require "../translations/tr.json")
:vi (js/require "../translations/vi.json")
:zh (js/require "../translations/zh.json")
:zh_Hant (js/require "../translations/zh_hant.json")
:zh_TW (js/require "../translations/zh_TW.json"))))
(def translations-by-locale
(cond-> {:en (require-translation :en)}
(not= :en default-device-language)
(assoc default-device-language
(require-translation (-> (name default-device-language)
(string/replace "-" "_")
keyword)))))
(set! (.-fallbacks i18n) true)
(set! (.-defaultSeparator i18n) "/")
(set! (.-locale i18n) (name default-device-language))
(set! (.-translations i18n) (clj->js translations-by-locale))
(defn init
[]
(set! (.-fallbacks i18n) true) (set! (.-fallbacks i18n) true)
(set! (.-defaultSeparator i18n) "/") (set! (.-defaultSeparator i18n) "/")
(set! (.-locale i18n) (name default-device-language)) (set! (.-locale i18n) default-device-language)
(set! (.-translations i18n) (clj->js translations-by-locale))) (set! (.-translations i18n) translations-by-locale))
(defn get-translations (defn get-translations
[] []
@ -134,12 +70,3 @@
(.-locale i18n)) (.-locale i18n))
(def format-currency goog.i18n/format-currency) (def format-currency goog.i18n/format-currency)
(defn load-language
[lang loaded-languages]
(when-let [lang-key (valid-language (keyword lang))]
(when-not (contains? @loaded-languages lang-key)
(aset (i18n/get-translations)
lang
(require-translation lang-key))
(swap! loaded-languages conj lang-key))))

View File

@ -5,9 +5,7 @@
[shadow.test :as st] [shadow.test :as st]
[shadow.test.env :as env] [shadow.test.env :as env]
[utils.re-frame :as rf] [utils.re-frame :as rf]
[i18n.i18n :as i18n])) status-im2.setup.i18n-resources))
(i18n/init)
(defonce repl? (atom false)) (defonce repl? (atom false))

View File

@ -4,10 +4,11 @@
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[status-im.add-new.db :as db] [status-im.add-new.db :as db]
[status-im.chat.models :as chat.models] [status-im.chat.models :as chat.models]
[i18n.i18n :as i18n]
[status-im.react-native.resources :as resources] [status-im.react-native.resources :as resources]
[status-im.ui.components.icons.icons :as icons] [status-im.ui.components.icons.icons :as icons]
[status-im.ui.components.react :as react]) [status-im.ui.components.react :as react]
[status-im2.setup.i18n-resources :as i18n-resources]
[i18n.i18n :as i18n])
(:require-macros [status-im.utils.views :as views])) (:require-macros [status-im.utils.views :as views]))
(defn- start-chat (defn- start-chat
@ -73,8 +74,8 @@
(defn get-language-topic (defn get-language-topic
[] []
(let [lang (subs (name i18n/default-device-language) 0 2) (let [lang (subs (name i18n-resources/default-device-language) 0 2)
lang3 (subs (name i18n/default-device-language) 0 3) lang3 (subs (name i18n-resources/default-device-language) 0 3)
lang-name (or (get lang-names lang3) (get lang-names lang))] lang-name (or (get lang-names lang3) (get lang-names lang))]
(when-not (= lang "en") (when-not (= lang "en")
(or lang-name (str "status-" lang))))) (or lang-name (str "status-" lang)))))

View File

@ -5,7 +5,7 @@
[quo2.foundations.colors :as colors] [quo2.foundations.colors :as colors]
[react-native.core :as rn] [react-native.core :as rn]
[react-native.reanimated :as reanimated] [react-native.reanimated :as reanimated]
[status-im.ui2.screens.chat.pin-limit-popover.style :as style] ;; TODO move to status-im2 [status-im.ui2.screens.chat.pin-limit-popover.style :as style]
[utils.re-frame :as rf])) [utils.re-frame :as rf]))
;; TODO (flexsurfer) this should be an in-app notification component in quo2 ;; TODO (flexsurfer) this should be an in-app notification component in quo2
@ -56,6 +56,6 @@
:right 16}} :right 16}}
[quo/icon :i/close [quo/icon :i/close
{:color (colors/theme-colors colors/white colors/neutral-100) {:color (colors/theme-colors colors/white colors/neutral-100)
:size 8}]]]))]) :size 12}]]]))])

View File

@ -10,8 +10,7 @@
[status-im2.navigation.state :as state] [status-im2.navigation.state :as state]
[status-im2.navigation.view :as views] [status-im2.navigation.view :as views]
[taoensso.timbre :as log] [taoensso.timbre :as log]
[utils.re-frame :as rf] ;; TODO (14/11/22 flexsurfer) move to status-im2 namespace [utils.re-frame :as rf]))
))
;; REGISTER COMPONENT (LAZY) ;; REGISTER COMPONENT (LAZY)
(defn reg-comp (defn reg-comp

View File

@ -12,8 +12,7 @@
[status-im.ui.screens.signing.views :as signing] [status-im.ui.screens.signing.views :as signing]
[status-im.ui.screens.wallet-connect.session-proposal.views :as wallet-connect] [status-im.ui.screens.wallet-connect.session-proposal.views :as wallet-connect]
[status-im.ui.screens.wallet.send.views :as wallet.send.views] [status-im.ui.screens.wallet.send.views :as wallet.send.views]
[status-im2.common.toasts.view :as toasts] ;; TODO (14/11/22 flexsurfer) move to status-im2 [status-im2.common.toasts.view :as toasts]
;; namespace
[status-im2.navigation.screens :as screens] [status-im2.navigation.screens :as screens]
[status-im2.setup.config :as config] [status-im2.setup.config :as config]
[status-im2.setup.hot-reload :as reloader])) [status-im2.setup.hot-reload :as reloader]))

View File

@ -1,7 +1,6 @@
(ns status-im2.setup.config (ns status-im2.setup.config
(:require [clojure.string :as string] (:require [clojure.string :as string]
[react-native.config :as react-native-config] ;; TODO (14/11/22 flexsurfer move to status-im2 [react-native.config :as react-native-config]
;; namespace
[status-im.ethereum.core :as ethereum] [status-im.ethereum.core :as ethereum]
[status-im.ethereum.ens :as ens])) [status-im.ethereum.ens :as ens]))

View File

@ -1,6 +1,7 @@
(ns status-im2.setup.core (ns status-im2.setup.core
(:require (:require
[i18n.i18n :as i18n] [i18n.i18n :as i18n]
[status-im2.setup.i18n-resources :as i18n-resources]
[re-frame.core :as re-frame] [re-frame.core :as re-frame]
[re-frame.interop :as interop] [re-frame.interop :as interop]
[react-native.core :as rn] [react-native.core :as rn]
@ -13,8 +14,7 @@
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.notifications.local :as notifications] [status-im.notifications.local :as notifications]
[status-im.utils.universal-links.core :as utils.universal-links] [status-im.utils.universal-links.core :as utils.universal-links]
[status-im2.contexts.shell.animation :as animation] ;; TODO (14/11/22 flexsurfer move to [status-im2.contexts.shell.animation :as animation]
;; status-im2 namespace
status-im2.contexts.syncing.events status-im2.contexts.syncing.events
status-im2.navigation.core status-im2.navigation.core
[status-im2.setup.config :as config] [status-im2.setup.config :as config]
@ -22,7 +22,6 @@
status-im2.setup.events status-im2.setup.events
status-im2.setup.datetime status-im2.setup.datetime
[status-im2.setup.global-error :as global-error] [status-im2.setup.global-error :as global-error]
[status-im2.setup.i18n-resources :as i18n-resources]
[status-im2.setup.log :as log] [status-im2.setup.log :as log]
status-im2.subs.root)) status-im2.subs.root))
@ -32,19 +31,15 @@
(defn init (defn init
[] []
(log/setup config/log-level) (log/setup config/log-level)
(global-error/register-handler) (global-error/register-handler)
(when platform/android? (when platform/android?
(status/set-soft-input-mode status/adjust-resize)) (status/set-soft-input-mode status/adjust-resize))
(notifications/listen-notifications) (notifications/listen-notifications)
(.addEventListener rn/app-state "change" #(re-frame/dispatch [:app-state-change %])) (.addEventListener rn/app-state "change" #(re-frame/dispatch [:app-state-change %]))
(i18n/init) (react-native-languages/add-change-listener #(fn [lang]
(i18n/set-language lang)
(react-native-languages/add-change-listener (i18n-resources/load-language lang)))
#(fn [lang]
(i18n/load-language lang i18n-resources/loaded-languages)
(i18n/set-language lang)))
(react-native-shake/add-shake-listener #(re-frame/dispatch [:shake-event])) (react-native-shake/add-shake-listener #(re-frame/dispatch [:shake-event]))
(utils.universal-links/initialize) (utils.universal-links/initialize)

View File

@ -1,5 +1,5 @@
(ns status-im2.setup.db (ns status-im2.setup.db
(:require [react-native.core :as rn] ;; TODO (14/11/22 flexsurfer move to status-im2 namespace (:require [react-native.core :as rn]
[status-im.fleet.core :as fleet] [status-im.fleet.core :as fleet]
[status-im.wallet.db :as wallet.db] [status-im.wallet.db :as wallet.db]
[status-im2.contexts.activity-center.events :as activity-center])) [status-im2.contexts.activity-center.events :as activity-center]))

View File

@ -2,7 +2,7 @@
(:require [clojure.string :as string] (:require [clojure.string :as string]
[quo.theme :as quo.theme] [quo.theme :as quo.theme]
[quo2.theme :as quo2.theme] [quo2.theme :as quo2.theme]
[re-frame.core :as re-frame] ;; TODO (14/11/22 flexsurfer move to status-im2 namespace [re-frame.core :as re-frame]
[status-im.multiaccounts.login.core :as multiaccounts.login] [status-im.multiaccounts.login.core :as multiaccounts.login]
[status-im.native-module.core :as status] [status-im.native-module.core :as status]
[status-im.utils.keychain.core :as keychain] [status-im.utils.keychain.core :as keychain]

View File

@ -1,6 +1,78 @@
(ns status-im2.setup.i18n-resources (ns status-im2.setup.i18n-resources
(:require [i18n.i18n :as i18n])) (:require [clojure.string :as string]
[i18n.i18n :as i18n]
[react-native.languages :as react-native-languages]))
(def default-device-language (react-native-languages/get-lang-keyword))
(def languages
#{:ar :bn :de :el :en :es :es_419 :es_AR :fil :fr :hi :id :in :it :ja :ko :ms :nl :pl :pt :pt_BR :ru
:tr :vi :zh :zh_Hant :zh_TW})
(defonce loaded-languages (defonce loaded-languages
(atom (atom
(conj #{:en} i18n/default-device-language))) (conj #{:en} default-device-language)))
(defn valid-language
[lang]
(if (contains? languages 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? languages short-lang))
short-lang
(when (contains? languages shortest-lang)
shortest-lang)))))
(defn require-translation
[lang-key]
(when-let [lang (valid-language (keyword lang-key))]
(case lang
:ar (js/require "../translations/ar.json")
:bn (js/require "../translations/bn.json")
:de (js/require "../translations/de.json")
:el (js/require "../translations/el.json")
:en (js/require "../translations/en.json")
:es (js/require "../translations/es.json")
:es_419 (js/require "../translations/es_419.json")
:es_AR (js/require "../translations/es_AR.json")
:fil (js/require "../translations/fil.json")
:fr (js/require "../translations/fr.json")
:hi (js/require "../translations/hi.json")
:id (js/require "../translations/id.json")
:in (js/require "../translations/id.json")
:it (js/require "../translations/it.json")
:ja (js/require "../translations/ja.json")
:ko (js/require "../translations/ko.json")
:ms (js/require "../translations/ms.json")
:nl (js/require "../translations/nl.json")
:pl (js/require "../translations/pl.json")
:pt (js/require "../translations/pt.json")
:pt_BR (js/require "../translations/pt_BR.json")
:ru (js/require "../translations/ru.json")
:tr (js/require "../translations/tr.json")
:vi (js/require "../translations/vi.json")
:zh (js/require "../translations/zh.json")
:zh_Hant (js/require "../translations/zh_hant.json")
:zh_TW (js/require "../translations/zh_TW.json"))))
;; translations
(def translations-by-locale
(cond-> {:en (require-translation :en)}
(not= :en default-device-language)
(assoc default-device-language
(require-translation (-> (name default-device-language)
(string/replace "-" "_")
keyword)))))
(i18n/setup (name default-device-language) (clj->js translations-by-locale))
(defn load-language
[lang]
(when-let [lang-key (valid-language (keyword lang))]
(when-not (contains? @loaded-languages lang-key)
(aset (i18n/get-translations)
lang
(require-translation lang-key))
(swap! loaded-languages conj lang-key))))

View File

@ -3,11 +3,12 @@
[cljs.test :refer-macros [deftest is]] [cljs.test :refer-macros [deftest is]]
[clojure.set :as set] [clojure.set :as set]
[clojure.string :as string] [clojure.string :as string]
[i18n.i18n :as i18n])) [i18n.i18n :as i18n]
[status-im2.setup.i18n-resources :as i18n-resources]))
;; english as source of truth ;; english as source of truth
(def labels (def labels
(set (keys (js->clj (:en i18n/translations-by-locale) (set (keys (js->clj (:en i18n-resources/translations-by-locale)
:keywordize-keys :keywordize-keys
true)))) true))))
@ -16,7 +17,7 @@
(defn labels-for-all-locales (defn labels-for-all-locales
[] []
(->> i18n/translations-by-locale (->> i18n-resources/translations-by-locale
(mapcat #(-> % val (js->clj :keywordize-keys true) keys)) (mapcat #(-> % val (js->clj :keywordize-keys true) keys))
set)) set))
@ -1024,14 +1025,14 @@
;; locales ;; locales
(def locales (set (keys i18n/translations-by-locale))) (def locales (set (keys i18n-resources/translations-by-locale)))
(spec/def ::locale locales) (spec/def ::locale locales)
(spec/def ::locales (spec/coll-of ::locale :kind set? :into #{})) (spec/def ::locales (spec/coll-of ::locale :kind set? :into #{}))
(defn locale->labels (defn locale->labels
[locale] [locale]
(-> i18n/translations-by-locale (get locale) (js->clj :keywordize-keys true) keys set)) (-> i18n-resources/translations-by-locale (get locale) (js->clj :keywordize-keys true) keys set))
(defn locale->checkpoint (defn locale->checkpoint
[locale] [locale]

View File

@ -147,10 +147,9 @@
(re-frame/reg-sub (re-frame/reg-sub
:chats/sending-image :chats/sending-image
:<- [:chats/current-chat-id] :<- [:chats/current-chat-inputs]
:<- [:chat/inputs] (fn [{:keys [metadata]}]
(fn [[chat-id inputs]] (:sending-image metadata)))
(get-in inputs [chat-id :metadata :sending-image])))
(re-frame/reg-sub (re-frame/reg-sub
:chats/timeline-chat-input-text :chats/timeline-chat-input-text
@ -290,12 +289,6 @@
(fn [{:keys [metadata]}] (fn [{:keys [metadata]}]
(:sending-contact-request metadata))) (:sending-contact-request metadata)))
(re-frame/reg-sub
:chats/sending-image
:<- [:chats/current-chat-inputs]
(fn [{:keys [metadata]}]
(:sending-image metadata)))
(re-frame/reg-sub (re-frame/reg-sub
:chats/timeline-sending-image :chats/timeline-sending-image
:<- [:chats/timeline-chat-input] :<- [:chats/timeline-chat-input]