Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
TerenceGe committed Jun 29, 2018
1 parent 07449c7 commit 174ad90
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
6 changes: 3 additions & 3 deletions shared/sagas/intl.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { takeEvery } from 'redux-saga/effects'
import { takeEvery, call } from 'redux-saga/effects'
import { Action } from 'redux-actions'
import storage from 'utils/storage'
import * as actions from 'actions/intl'

function setLocale(action: Action<object>) {
storage.setItem('bitportal_lang', action.payload, false, {
function* setLocale(action: Action<object>) {
yield call(storage.setItem, 'bitportal_lang', action.payload, false, {
path: '/',
domain: 'bitportal.io',
expires: new Date(Date.now() + (3600 * 1000 * 24 * 365))
Expand Down
29 changes: 21 additions & 8 deletions shared/screens/Profile/Languages/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,21 +31,34 @@ export default class Languages extends BaseScreen {
navBarHidden: true
}

changeTabLabels = (tabLabels) => {
constructor(props, context) {
super(props, context)
this.state = {
locale: this.props.locale
}

this.switchLanguage = this.switchLanguage.bind(this)
this.changeTabLabels = this.changeTabLabels.bind(this)
}

changeTabLabels(tabLabels) {
this.props.navigator.setTabButton({ tabIndex: 0, label: tabLabels.general_tab_name_ast })
this.props.navigator.setTabButton({ tabIndex: 1, label: tabLabels.general_tab_name_mkt })
this.props.navigator.setTabButton({ tabIndex: 2, label: tabLabels.general_tab_name_dscv })
this.props.navigator.setTabButton({ tabIndex: 3, label: tabLabels.general_tab_name_prf })
}

switchLanguage = (language) => {
this.props.actions.setLocale(language)
const tabLabels = tabMessages[language]
this.changeTabLabels(tabLabels)
switchLanguage(language) {
this.setState({ locale: language }, () => {
this.props.actions.setLocale(language)
const tabLabels = tabMessages[language]
this.changeTabLabels(tabLabels)
})
}

render() {
const { locale } = this.props
const locale = this.state.locale || this.props.locale

return (
<IntlProvider messages={messages[locale]}>
<View style={styles.container}>
Expand All @@ -57,7 +70,7 @@ export default class Languages extends BaseScreen {
<ScrollView showsVerticalScrollIndicator={false}>
<SettingItem
leftItemTitle="English"
onPress={() => this.switchLanguage('en')}
onPress={this.switchLanguage.bind(this, 'en')}
extraStyle={{ marginTop: 10 }}
iconColor={Colors.bgColor_0_122_255}
rightItemTitle={locale === 'en' ? null : ' '}
Expand All @@ -68,7 +81,7 @@ export default class Languages extends BaseScreen {
iconColor={Colors.bgColor_0_122_255}
rightItemTitle={locale === 'zh' ? null : ' '}
rightImageName={locale === 'zh' && 'md-checkmark'}
onPress={() => this.switchLanguage('zh')}
onPress={this.switchLanguage.bind(this, 'zh')}
/>
</ScrollView>
</View>
Expand Down

0 comments on commit 174ad90

Please sign in to comment.