import React, { Component } from 'react'; import { DevSettings } from 'react-native'; import { Platform, StyleSheet, TouchableOpacity, Text, ScrollView, View } from 'react-native'; import I18n from './i18n'; import AsyncStorage from '@react-native-community/async-storage' const STORAGE_KEY = "language" const language = [ {lang: {I18n.t('language.English')}, code: "en"}, {lang: {I18n.t('language.Spanish')}, code: "es"}, ] 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 ( this.onSelectedLang(data)}> {data.lang} ) }) ) } 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 ( {I18n.t('language.note')} {this.state.select} {(this.state.value) ? this.onSelectLanguage() : null} ); } }