2016-05-25 01:27:03 +00:00
|
|
|
(ns status-im.i18n
|
|
|
|
(:require
|
2016-11-22 12:50:52 +00:00
|
|
|
[status-im.translations.af :as af]
|
|
|
|
[status-im.translations.ar :as ar]
|
2017-05-08 20:59:58 +00:00
|
|
|
[status-im.translations.da :as da]
|
2016-11-22 12:50:52 +00:00
|
|
|
[status-im.translations.de :as de]
|
|
|
|
[status-im.translations.de-ch :as de-ch]
|
2016-05-29 18:14:34 +00:00
|
|
|
[status-im.translations.en :as en]
|
2016-11-22 12:50:52 +00:00
|
|
|
[status-im.translations.es :as es]
|
|
|
|
[status-im.translations.es-ar :as es-ar]
|
|
|
|
[status-im.translations.fr :as fr]
|
|
|
|
[status-im.translations.fr-ch :as fr-ch]
|
|
|
|
[status-im.translations.hi :as hi]
|
|
|
|
[status-im.translations.hu :as hu]
|
2017-04-26 05:00:32 +00:00
|
|
|
[status-im.translations.id :as id]
|
2016-11-22 12:50:52 +00:00
|
|
|
[status-im.translations.it :as it]
|
|
|
|
[status-im.translations.it-ch :as it-ch]
|
|
|
|
[status-im.translations.ja :as ja]
|
|
|
|
[status-im.translations.ko :as ko]
|
|
|
|
[status-im.translations.nl :as nl]
|
|
|
|
[status-im.translations.pl :as pl]
|
|
|
|
[status-im.translations.pt-br :as pt-br]
|
|
|
|
[status-im.translations.pt-pt :as pt-pt]
|
|
|
|
[status-im.translations.ro :as ro]
|
|
|
|
[status-im.translations.ru :as ru]
|
|
|
|
[status-im.translations.sl :as sl]
|
|
|
|
[status-im.translations.sv :as sv]
|
|
|
|
[status-im.translations.sw :as sw]
|
|
|
|
[status-im.translations.th :as th]
|
|
|
|
[status-im.translations.tr :as tr]
|
|
|
|
[status-im.translations.uk :as uk]
|
|
|
|
[status-im.translations.ur :as ur]
|
|
|
|
[status-im.translations.vi :as vi]
|
|
|
|
[status-im.translations.zh-hans :as zh-hans]
|
|
|
|
[status-im.translations.zh-hant :as zh-hant]
|
|
|
|
[status-im.translations.zh-wuu :as zh-wuu]
|
|
|
|
[status-im.translations.zh-yue :as zh-yue]
|
2017-01-23 15:57:40 +00:00
|
|
|
[status-im.utils.js-resources :refer [default-contacts]]
|
|
|
|
[taoensso.timbre :as log]
|
|
|
|
[clojure.string :as str]))
|
2016-05-25 01:27:03 +00:00
|
|
|
|
2016-10-24 20:46:06 +00:00
|
|
|
(def i18n (js/require "react-native-i18n"))
|
2016-05-27 16:44:06 +00:00
|
|
|
(set! (.-fallbacks i18n) true)
|
|
|
|
(set! (.-defaultSeparator i18n) "/")
|
2016-05-25 01:27:03 +00:00
|
|
|
|
2016-11-22 12:50:52 +00:00
|
|
|
(set! (.-translations i18n) (clj->js {:af af/translations
|
|
|
|
:ar ar/translations
|
2017-05-08 20:59:58 +00:00
|
|
|
:da da/translations
|
2016-11-22 12:50:52 +00:00
|
|
|
:de de/translations
|
|
|
|
:de-ch de-ch/translations
|
|
|
|
:en en/translations
|
|
|
|
:es es/translations
|
|
|
|
:es-ar es-ar/translations
|
|
|
|
:fr fr/translations
|
|
|
|
:fr-ch fr-ch/translations
|
|
|
|
:hi hi/translations
|
|
|
|
:hu hu/translations
|
2017-04-26 05:00:32 +00:00
|
|
|
:id id/translations
|
2016-11-22 12:50:52 +00:00
|
|
|
:it it/translations
|
|
|
|
:it-ch it-ch/translations
|
|
|
|
:ja ja/translations
|
|
|
|
:ko ko/translations
|
|
|
|
:nl nl/translations
|
|
|
|
:pl pl/translations
|
|
|
|
:pt-br pt-br/translations
|
|
|
|
:pt-pt pt-pt/translations
|
|
|
|
:ro ro/translations
|
|
|
|
:ru ru/translations
|
|
|
|
:sl sl/translations
|
|
|
|
:sv sv/translations
|
|
|
|
:sw sw/translations
|
|
|
|
:th th/translations
|
|
|
|
:tr tr/translations
|
|
|
|
:uk uk/translations
|
|
|
|
:ur ur/translations
|
|
|
|
:vi vi/translations
|
|
|
|
:zh-hans zh-hans/translations
|
|
|
|
:zh-hant zh-hant/translations
|
|
|
|
:zh-wuu zh-wuu/translations
|
|
|
|
:zh-yue zh-yue/translations}))
|
2016-05-25 01:27:03 +00:00
|
|
|
|
2017-01-23 15:57:40 +00:00
|
|
|
(def delimeters
|
|
|
|
"This function is a hack: mobile Safari doesn't support toLocaleString(), so we need to pass
|
|
|
|
this map to WKWebView to make number formatting work."
|
2017-02-02 06:51:26 +00:00
|
|
|
(let [n (.toLocaleString (js/Number 1000.1))
|
|
|
|
delimiter? (= (count n) 7)]
|
|
|
|
(if delimiter?
|
|
|
|
{:delimiter (subs n 1 2)
|
|
|
|
:separator (subs n 5 6)}
|
|
|
|
{:delimiter ""
|
|
|
|
:separator (subs n 4 5)})))
|
2017-01-23 15:57:40 +00:00
|
|
|
|
|
|
|
(defn label-number [number]
|
|
|
|
(when number
|
|
|
|
(let [{:keys [delimiter separator]} delimeters]
|
|
|
|
(.toNumber i18n
|
|
|
|
(str/replace number #"," ".")
|
|
|
|
(clj->js {:precision 10
|
|
|
|
:strip_insignificant_zeros true
|
|
|
|
:delimiter delimiter
|
|
|
|
:separator separator})))))
|
|
|
|
|
2016-06-02 12:48:57 +00:00
|
|
|
(defn label
|
|
|
|
([path] (label path {}))
|
|
|
|
([path options]
|
2016-06-10 00:21:48 +00:00
|
|
|
(if (exists? i18n.t)
|
2017-01-23 15:57:40 +00:00
|
|
|
(let [options (update options :amount label-number)]
|
|
|
|
(.t i18n (name path) (clj->js options)))
|
2016-06-10 00:21:48 +00:00
|
|
|
(name path))))
|
2016-06-01 11:35:22 +00:00
|
|
|
|
2016-06-01 11:44:04 +00:00
|
|
|
(defn label-pluralize [count path & options]
|
2016-06-01 16:11:51 +00:00
|
|
|
(if (exists? i18n.t)
|
|
|
|
(.p i18n count (name path) (clj->js options))
|
2016-08-24 07:29:40 +00:00
|
|
|
(name path)))
|
|
|
|
|
|
|
|
(defn message-status-label [status]
|
|
|
|
(->> status
|
|
|
|
(name)
|
|
|
|
(str "t/status-")
|
|
|
|
(keyword)
|
2016-10-24 20:46:06 +00:00
|
|
|
(label)))
|
2016-12-28 10:00:21 +00:00
|
|
|
|
|
|
|
(def locale
|
|
|
|
(.-locale i18n))
|
|
|
|
|
|
|
|
(defn get-contact-translated [contact-id key fallback]
|
|
|
|
(let [translation #(get-in default-contacts [(keyword contact-id) key (keyword %)])]
|
|
|
|
(or (translation locale)
|
|
|
|
(translation (subs locale 0 2))
|
|
|
|
fallback)))
|