Merge pull request #589 from status-im/feature/#334

Translations for DApps (#334)
This commit is contained in:
Roman Volosovskyi 2017-01-02 12:38:56 +02:00 committed by GitHub
commit 206f336dff
11 changed files with 74 additions and 35 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

After

Width:  |  Height:  |  Size: 8.8 KiB

View File

@ -1,13 +1,29 @@
[
{"id": "wallet",
"name": "Wallet",
"photo-path": "icon_wallet_avatar",
"add-chat?": true,
"dapp?": true},
{
"wallet":
{
"name":
{
"en": "Wallet",
"es": "Monedero",
"es-ar": "Monedero",
"ru": "Кошелек"
},
"photo-path": "icon_wallet_avatar",
"add-chat?": true,
"dapp?": true
},
{"id": "dapp-auction-house",
"name": "Auction House",
"photo-path": "contacts://auction-house",
"dapp?": true,
"dapp-url": "http://auctionhouse.dappbench.com"}
]
"auction-house":
{
"name":
{
"en": "Auction House"
},
"photo-path": "contacts://auction-house",
"dapp?": true,
"dapp-url":
{
"en": "http://auctionhouse.dappbench.com"
}
}
}

View File

@ -29,7 +29,8 @@
[status-im.components.chat-icon.screen :refer [chat-icon-message-status]]
[status-im.utils.identicon :refer [identicon]]
[status-im.utils.gfycat.core :refer [generate-gfy]]
[status-im.i18n :refer [label]]
[status-im.i18n :refer [label
get-contact-translated]]
[status-im.chat.utils :as cu]
[clojure.string :as str]
[status-im.chat.handlers.console :as console]
@ -55,7 +56,8 @@
:number-of-lines 1}
(if (str/blank? @name)
(generate-gfy)
(or @name (label :t/chat-name)))]
(or (get-contact-translated @chat-id :name @name)
(label :t/chat-name)))]
(when (or status content)
[text {:style st/status-text
:font :default}

View File

@ -6,7 +6,9 @@
[status-im.components.react :refer [view
text
icon]]
[status-im.i18n :refer [label label-pluralize]]
[status-im.i18n :refer [get-contact-translated
label
label-pluralize]]
[status-im.chat.styles.screen :as st]
[status-im.components.refreshable-text.view :refer [refreshable-text]]
[status-im.utils.datetime :as time]
@ -75,7 +77,8 @@
:font :toolbar-title}
(if (str/blank? @name)
(generate-gfy)
(or @name (label :t/chat-name)))]
(or (get-contact-translated @chat-id :name @name)
(label :t/chat-name)))]
(if @group-chat
[group-last-activity {:contacts @contacts
:sync-state @sync-state}]

View File

@ -7,7 +7,7 @@
[status-im.models.commands :refer [parse-command-message-content]]
[status-im.chats-list.styles :as st]
[status-im.utils.utils :refer [truncate-str]]
[status-im.i18n :refer [label label-pluralize]]
[status-im.i18n :refer [get-contact-translated label label-pluralize]]
[status-im.utils.datetime :as time]
[status-im.utils.gfycat.core :refer [generate-gfy]]
[status-im.constants :refer [console-chat-id
@ -80,7 +80,8 @@
online group-chat contacts] :as chat}]
(let [last-message (or (first (sort-by :clock-value > (:messages chat)))
last-message)
name (or name (generate-gfy))]
name (or (get-contact-translated chat-id :name name)
(generate-gfy))]
[view st/chat-container
[view st/chat-icon-container
[chat-icon-view-chat-list chat-id group-chat name color online]]

View File

@ -9,6 +9,7 @@
[status-im.components.react :as r]
[status-im.models.commands :as cm]
[status-im.constants :refer [console-chat-id]]
[status-im.i18n :refer [get-contact-translated]]
[taoensso.timbre :as log]))
(defn render-command
@ -47,7 +48,7 @@
{:keys [dapp? dapp-url]} (get contacts chat-id)
hiccup (generate-hiccup markup)
web-view-url (if (and (= webViewUrl "dapp-url") dapp? dapp-url)
dapp-url
(get-contact-translated chat-id :dapp-url dapp-url)
webViewUrl)]
(-> db
(assoc-in [:suggestions chat-id] hiccup)

View File

@ -167,16 +167,16 @@
(reg-handler :load-default-contacts!
(u/side-effect!
(fn [{:keys [chats]}]
(let [contacts (json->clj js-res/default-contacts-js)]
(doseq [{:keys [id name photo-path public-key add-chat?
dapp? dapp-url dapp-hash] :as contact} contacts]
(doseq [[id {:keys [name photo-path public-key add-chat?
dapp? dapp-url dapp-hash] :as contact}] js-res/default-contacts]
(let [id (clojure.core/name id)]
(when-not (chats id)
(when add-chat?
(dispatch [:add-chat id {:name name}]))
(dispatch [:add-chat id {:name (:en name)}]))
(dispatch [:add-contacts [{:whisper-identity id
:name name
:name (:en name)
:photo-path photo-path
:public-key public-key
:dapp? dapp?
:dapp-url dapp-url
:dapp-url (:en dapp-url)
:dapp-hash dapp-hash}]])))))))

View File

@ -4,7 +4,7 @@
[status-im.components.chat-icon.screen :refer [contact-icon-contacts-tab]]
[status-im.contacts.styles :as st]
[status-im.utils.gfycat.core :refer [generate-gfy]]
[status-im.i18n :refer [label]]))
[status-im.i18n :refer [get-contact-translated label]]))
(defn contact-photo [contact]
[view st/contact-photo-container
@ -13,14 +13,14 @@
(defn contact-inner-view
([contact]
(contact-inner-view contact nil))
([{:keys [name] :as contact} info]
([{:keys [whisper-identity name] :as contact} info]
[view st/contact-inner-container
[contact-photo contact]
[view st/info-container
[text {:style st/name-text
:number-of-lines 1}
(if (pos? (count (:name contact)))
name
(get-contact-translated whisper-identity :name name)
;; todo is this correct behaviour?
(generate-gfy))]
(when info

View File

@ -33,7 +33,8 @@
[status-im.translations.zh-hant :as zh-hant]
[status-im.translations.zh-wuu :as zh-wuu]
[status-im.translations.zh-yue :as zh-yue]
[status-im.utils.utils :as u]))
[status-im.utils.utils :as u]
[status-im.utils.js-resources :refer [default-contacts]]))
(def i18n (js/require "react-native-i18n"))
(set! (.-fallbacks i18n) true)
@ -91,3 +92,12 @@
(str "t/status-")
(keyword)
(label)))
(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)))

View File

@ -32,7 +32,8 @@
[status-im.utils.random :refer [id]]
[status-im.utils.utils :refer [clean-text]]
[status-im.components.image-button.view :refer [show-qr-button]]
[status-im.i18n :refer [label]]))
[status-im.i18n :refer [label
get-contact-translated]]))
(defn share [text dialog-title]
(let [list-selection-fn (:list-selection-fn platform-specific)]
@ -72,8 +73,11 @@
(r/set-state component {:height height}))]
(r/create-class
{:reagent-render
(fn [{{:keys [name status photo-path]} :account
edit? :edit?}]
(fn [{{:keys [whisper-identity
name
status
photo-path]} :account
edit? :edit?}]
[view st/status-block
[view st/user-photo-container
@ -94,7 +98,7 @@
:editable edit?
:input-style (st/username-input edit? (s/valid? ::v/name name))
:wrapper-style st/username-wrapper
:value name
:value (get-contact-translated whisper-identity :name name)
:on-change-text #(dispatch [:set-in [:profile-edit :name] %])}]
(if (or edit? @just-opened?)
[text-input {:ref #(reset! input-ref %)

View File

@ -1,7 +1,9 @@
(ns ^:figwheel-always status-im.utils.js-resources
(:require-macros [status-im.utils.slurp :refer [slurp]]))
(:require-macros [status-im.utils.slurp :refer [slurp]])
(:require [status-im.utils.types :refer [json->clj]]))
(def default-contacts-js (slurp "resources/default_contacts.json"))
(def default-contacts (-> (slurp "resources/default_contacts.json")
(json->clj)))
(def commands-js (slurp "resources/commands.js"))
(def console-js (slurp "resources/console.js"))