blazerapp/app/Language.js

74 lines
1.9 KiB
JavaScript
Raw Permalink Normal View History

2021-08-17 21:18:32 -04:00
import React, { Component } from 'react';
2021-01-01 00:23:17 -05:00
import { DevSettings } from 'react-native';
import { Platform, StyleSheet, TouchableOpacity, Text, ScrollView, View } from 'react-native';
import I18n from './i18n';
2021-08-17 21:18:32 -04:00
import AsyncStorage from '@react-native-async-storage/async-storage'
2021-01-01 00:23:17 -05:00
const STORAGE_KEY = "language"
const language = [
2021-08-17 21:18:32 -04:00
{lang: <Text>English</Text>, code: "en-US"},
{lang: <Text>Spanish</Text>, code: "es-US"},
2021-01-01 00:23:17 -05:00
]
export default class extends Component {
constructor() {
super();
this.state = {
languages: [],
value: false,
select: I18n.t('language.SelectLanguage'),
}
this.onLanguage=this.onLanguage.bind(this);
}
onSelectLanguage() {
return(
language.map((data, i)=>{
return (
<View key={i} style={{backgroundColor: "#f99", padding: 10}}>
<TouchableOpacity onPress={()=>this.onSelectedLang(data)}>
<Text style={{paddingTop: 2, color: "#fff", fontSize: 18}}>{data.lang}</Text>
</TouchableOpacity>
</View>
)
})
)
}
onSelectedLang(text) {
this.setState({
value: false,
select: text.lang,
}),
I18n.locale = text.code
AsyncStorage.setItem('language', text.code)
DevSettings.reload()
}
onLanguage() {
this.setState({
value: true,
})
}
render() {
return (
<View style={{flex: 1, backgroundColor: 'white', padding: 24}}>
<Text style ={{marginBottom: 5}}>{I18n.t('language.note')}</Text>
<View>
<TouchableOpacity onPress={this.onLanguage}>
<View style={{backgroundColor: "red", padding: 10}}>
<Text style={{color: "white", fontSize: 18, fontWeight: 'bold'}}>{this.state.select}</Text>
</View>
</TouchableOpacity>
<View>
{(this.state.value) ? this.onSelectLanguage() : null}
</View>
</View>
</View>
);
}
2021-08-17 21:18:32 -04:00
}