Use phone's locale for phone number internationalization

This commit is contained in:
virvar 2016-03-21 13:53:21 +03:00
parent f8a5237f44
commit b21b4ecc1a
4 changed files with 14 additions and 11 deletions

View File

@ -7,7 +7,8 @@
"react-native-invertible-scroll-view",
"awesome-phonenumber",
"realm",
"react-native-loading-spinner-overlay"
"react-native-loading-spinner-overlay",
"react-native-i18n"
],
"imageDirs": [
"images"

View File

@ -8,6 +8,7 @@
[messenger.state :as state]
[messenger.comm.intercom :as intercom :refer [set-user-phone-number]]
[messenger.utils.utils :refer [log toast http-post]]
[messenger.utils.phone-number :refer [format-phone-number]]
[messenger.utils.resources :as res]
[messenger.components.spinner :refer [spinner]]
[messenger.android.sign-up-confirm :refer [sign-up-confirm]]
@ -15,9 +16,6 @@
(def nav-atom (atom nil))
(set! js/PhoneNumber (js/require "awesome-phonenumber"))
(def country-code "US")
(defn show-confirm-view []
(swap! state/app-state assoc :loading false)
(binding [state/*nav-render* false]
@ -32,7 +30,7 @@
(intercom/sign-up phone-number whisper-identity show-confirm-view)))
(defn update-phone-number [value]
(let [formatted (str (.getNumber (js/PhoneNumber. value country-code "international")))]
(let [formatted (format-phone-number value)]
(set-user-phone-number formatted)))
(defui Login

View File

@ -4,16 +4,11 @@
[cljs.core.async :as async :refer [chan put! <!]]
[messenger.utils.utils :refer [log on-error http-post toast]]
[messenger.utils.crypt :refer [encrypt]]
[messenger.utils.phone-number :refer [format-phone-number]]
[messenger.comm.intercom :as intercom :refer [save-user-phone-number]]
[messenger.models.contacts :as contacts-model]
[syng-im.utils.logging :as log]))
(set! js/PhoneNumber (js/require "awesome-phonenumber"))
(def country-code "US")
(defn- format-phone-number [number]
(str (.getNumber (js/PhoneNumber. number country-code "international"))))
(defn- get-contact-name [phone-contact]
(cstr/join " "
(filter #(not (cstr/blank? %))

View File

@ -0,0 +1,9 @@
(ns messenger.utils.phone-number)
(def i18n (js/require "react-native-i18n"))
(def locale (.-locale i18n))
(def country-code (subs locale 3 5))
(set! js/PhoneNumber (js/require "awesome-phonenumber"))
(defn format-phone-number [number]
(str (.getNumber (js/PhoneNumber. number country-code "international"))))