From 06bb8c6348d147dabf5d0ef352dd322bcf24a19a Mon Sep 17 00:00:00 2001 From: gnl Date: Mon, 16 Jul 2018 15:23:57 +0300 Subject: [PATCH] [FIX #4848] ui, i18n: Replace currency indicator with ~ Signed-off-by: Goran Jovic --- src/status_im/i18n.cljs | 149 ++++++++++++---------- src/status_im/ui/screens/wallet/subs.cljs | 3 +- 2 files changed, 81 insertions(+), 71 deletions(-) diff --git a/src/status_im/i18n.cljs b/src/status_im/i18n.cljs index 62c367f7c5..85d15e5021 100644 --- a/src/status_im/i18n.cljs +++ b/src/status_im/i18n.cljs @@ -389,74 +389,83 @@ (translation (subs locale 0 2)) fallback))) -(defn format-currency [value currency-code] - (.addTier2Support goog.i18n.currency) +(defn format-currency + ([value currency-code] + (format-currency value currency-code true)) + ([value currency-code currency-symbol?] + (.addTier2Support goog.i18n.currency) + (let [currency-code-to-nfs-map {"ZAR" (.-NumberFormatSymbols_af goog.i18n) + "ETB" (.-NumberFormatSymbols_am goog.i18n) + "EGP" (.-NumberFormatSymbols_ar goog.i18n) + "DZD" (.-NumberFormatSymbols_ar_DZ goog.i18n) + "AZN" (.-NumberFormatSymbols_az goog.i18n) + "BYN" (.-NumberFormatSymbols_be goog.i18n) + "BGN" (.-NumberFormatSymbols_bg goog.i18n) + "BDT" (.-NumberFormatSymbols_bn goog.i18n) + "EUR" (.-NumberFormatSymbols_br goog.i18n) + "BAM" (.-NumberFormatSymbols_bs goog.i18n) + "USD" (.-NumberFormatSymbols_en goog.i18n) + "CZK" (.-NumberFormatSymbols_cs goog.i18n) + "GBP" (.-NumberFormatSymbols_cy goog.i18n) + "DKK" (.-NumberFormatSymbols_da goog.i18n) + "CHF" (.-NumberFormatSymbols_de_CH goog.i18n) + "AUD" (.-NumberFormatSymbols_en_AU goog.i18n) + "CAD" (.-NumberFormatSymbols_en_CA goog.i18n) + "INR" (.-NumberFormatSymbols_en_IN goog.i18n) + "SGD" (.-NumberFormatSymbols_en_SG goog.i18n) + "MXN" (.-NumberFormatSymbols_es_419 goog.i18n) + "IRR" (.-NumberFormatSymbols_fa goog.i18n) + "PHP" (.-NumberFormatSymbols_fil goog.i18n) + "ILS" (.-NumberFormatSymbols_he goog.i18n) + "HRK" (.-NumberFormatSymbols_hr goog.i18n) + "HUF" (.-NumberFormatSymbols_hu goog.i18n) + "AMD" (.-NumberFormatSymbols_hy goog.i18n) + "IDR" (.-NumberFormatSymbols_id goog.i18n) + "ISK" (.-NumberFormatSymbols_is goog.i18n) + "JPY" (.-NumberFormatSymbols_ja goog.i18n) + "GEL" (.-NumberFormatSymbols_ka goog.i18n) + "KZT" (.-NumberFormatSymbols_kk goog.i18n) + "KHR" (.-NumberFormatSymbols_km goog.i18n) + "KRW" (.-NumberFormatSymbols_ko goog.i18n) + "KGS" (.-NumberFormatSymbols_ky goog.i18n) + "CDF" (.-NumberFormatSymbols_ln goog.i18n) + "LAK" (.-NumberFormatSymbols_lo goog.i18n) + "MKD" (.-NumberFormatSymbols_mk goog.i18n) + "MNT" (.-NumberFormatSymbols_mn goog.i18n) + "MDL" (.-NumberFormatSymbols_mo goog.i18n) + "MYR" (.-NumberFormatSymbols_ms goog.i18n) + "MMK" (.-NumberFormatSymbols_my goog.i18n) + "NOK" (.-NumberFormatSymbols_nb goog.i18n) + "NPR" (.-NumberFormatSymbols_ne goog.i18n) + "PLN" (.-NumberFormatSymbols_pl goog.i18n) + "BRL" (.-NumberFormatSymbols_pt goog.i18n) + "RON" (.-NumberFormatSymbols_ro goog.i18n) + "RUB" (.-NumberFormatSymbols_ru goog.i18n) + "RSD" (.-NumberFormatSymbols_sh goog.i18n) + "LKR" (.-NumberFormatSymbols_si goog.i18n) + "ALL" (.-NumberFormatSymbols_sq goog.i18n) + "SEK" (.-NumberFormatSymbols_sv goog.i18n) + "TZS" (.-NumberFormatSymbols_sw goog.i18n) + "THB" (.-NumberFormatSymbols_th goog.i18n) + "TRY" (.-NumberFormatSymbols_tr goog.i18n) + "UAH" (.-NumberFormatSymbols_uk goog.i18n) + "PKR" (.-NumberFormatSymbols_ur goog.i18n) + "UZS" (.-NumberFormatSymbols_uz goog.i18n) + "VND" (.-NumberFormatSymbols_vi goog.i18n) + "CNY" (.-NumberFormatSymbols_zh goog.i18n) + "HKD" (.-NumberFormatSymbols_zh_HK goog.i18n) + "TWD" (.-NumberFormatSymbols_zh_TW goog.i18n)} + nfs (or (get currency-code-to-nfs-map currency-code) + (.-NumberFormatSymbols_en goog.i18n))] + (set! (.-NumberFormatSymbols goog.i18n) + (if currency-symbol? + nfs + (-> nfs + (js->clj :keywordize-keys true) + ;; Remove any currency symbol placeholders in the pattern + (update-in [:CURRENCY_PATTERN] #(string/replace % #"\s*ยค\s*" "")) + clj->js))) + (.format + (new goog.i18n.NumberFormat (.-CURRENCY goog.i18n.NumberFormat.Format) currency-code) + value)))) - (def currency-code-to-nfs-map - {"ZAR" (.-NumberFormatSymbols_af goog.i18n) - "ETB" (.-NumberFormatSymbols_am goog.i18n) - "EGP" (.-NumberFormatSymbols_ar goog.i18n) - "DZD" (.-NumberFormatSymbols_ar_DZ goog.i18n) - "AZN" (.-NumberFormatSymbols_az goog.i18n) - "BYN" (.-NumberFormatSymbols_be goog.i18n) - "BGN" (.-NumberFormatSymbols_bg goog.i18n) - "BDT" (.-NumberFormatSymbols_bn goog.i18n) - "EUR" (.-NumberFormatSymbols_br goog.i18n) - "BAM" (.-NumberFormatSymbols_bs goog.i18n) - "USD" (.-NumberFormatSymbols_en goog.i18n) - "CZK" (.-NumberFormatSymbols_cs goog.i18n) - "GBP" (.-NumberFormatSymbols_cy goog.i18n) - "DKK" (.-NumberFormatSymbols_da goog.i18n) - "CHF" (.-NumberFormatSymbols_de_CH goog.i18n) - "AUD" (.-NumberFormatSymbols_en_AU goog.i18n) - "CAD" (.-NumberFormatSymbols_en_CA goog.i18n) - "INR" (.-NumberFormatSymbols_en_IN goog.i18n) - "SGD" (.-NumberFormatSymbols_en_SG goog.i18n) - "MXN" (.-NumberFormatSymbols_es_419 goog.i18n) - "IRR" (.-NumberFormatSymbols_fa goog.i18n) - "PHP" (.-NumberFormatSymbols_fil goog.i18n) - "ILS" (.-NumberFormatSymbols_he goog.i18n) - "HRK" (.-NumberFormatSymbols_hr goog.i18n) - "HUF" (.-NumberFormatSymbols_hu goog.i18n) - "AMD" (.-NumberFormatSymbols_hy goog.i18n) - "IDR" (.-NumberFormatSymbols_id goog.i18n) - "ISK" (.-NumberFormatSymbols_is goog.i18n) - "JPY" (.-NumberFormatSymbols_ja goog.i18n) - "GEL" (.-NumberFormatSymbols_ka goog.i18n) - "KZT" (.-NumberFormatSymbols_kk goog.i18n) - "KHR" (.-NumberFormatSymbols_km goog.i18n) - "KRW" (.-NumberFormatSymbols_ko goog.i18n) - "KGS" (.-NumberFormatSymbols_ky goog.i18n) - "CDF" (.-NumberFormatSymbols_ln goog.i18n) - "LAK" (.-NumberFormatSymbols_lo goog.i18n) - "MKD" (.-NumberFormatSymbols_mk goog.i18n) - "MNT" (.-NumberFormatSymbols_mn goog.i18n) - "MDL" (.-NumberFormatSymbols_mo goog.i18n) - "MYR" (.-NumberFormatSymbols_ms goog.i18n) - "MMK" (.-NumberFormatSymbols_my goog.i18n) - "NOK" (.-NumberFormatSymbols_nb goog.i18n) - "NPR" (.-NumberFormatSymbols_ne goog.i18n) - "PLN" (.-NumberFormatSymbols_pl goog.i18n) - "BRL" (.-NumberFormatSymbols_pt goog.i18n) - "RON" (.-NumberFormatSymbols_ro goog.i18n) - "RUB" (.-NumberFormatSymbols_ru goog.i18n) - "RSD" (.-NumberFormatSymbols_sh goog.i18n) - "LKR" (.-NumberFormatSymbols_si goog.i18n) - "ALL" (.-NumberFormatSymbols_sq goog.i18n) - "SEK" (.-NumberFormatSymbols_sv goog.i18n) - "TZS" (.-NumberFormatSymbols_sw goog.i18n) - "THB" (.-NumberFormatSymbols_th goog.i18n) - "TRY" (.-NumberFormatSymbols_tr goog.i18n) - "UAH" (.-NumberFormatSymbols_uk goog.i18n) - "PKR" (.-NumberFormatSymbols_ur goog.i18n) - "UZS" (.-NumberFormatSymbols_uz goog.i18n) - "VND" (.-NumberFormatSymbols_vi goog.i18n) - "CNY" (.-NumberFormatSymbols_zh goog.i18n) - "HKD" (.-NumberFormatSymbols_zh_HK goog.i18n) - "TWD" (.-NumberFormatSymbols_zh_TW goog.i18n)}) - - (def custom-nfs (currency-code-to-nfs-map currency-code)) - (set! (.-NumberFormatSymbols goog.i18n) (if custom-nfs custom-nfs (.-NumberFormatSymbols_en goog.i18n))) - (.format - (new goog.i18n.NumberFormat (.-CURRENCY goog.i18n.NumberFormat.Format) currency-code) - value)) diff --git a/src/status_im/ui/screens/wallet/subs.cljs b/src/status_im/ui/screens/wallet/subs.cljs index 14d76919f5..5073ebd2e9 100644 --- a/src/status_im/ui/screens/wallet/subs.cljs +++ b/src/status_im/ui/screens/wallet/subs.cljs @@ -68,7 +68,8 @@ (-> balance-total-value (money/with-precision 2) str - (i18n/format-currency (:code currency)))) + (i18n/format-currency (:code currency) false) + (->> (str "~")))) "..."))) (re-frame/reg-sub :prices-loading?