BlueWallet/screen/settings/language.js

102 lines
3.2 KiB
JavaScript
Raw Normal View History

import React, { Component } from 'react';
import { FlatList, TouchableOpacity } from 'react-native';
import { BlueLoading, BlueText, SafeBlueArea, BlueListItem, BlueCard, BlueNavigationStyle } from '../../BlueComponents';
import PropTypes from 'prop-types';
import { Icon } from 'react-native-elements';
let loc = require('../../loc');
export default class Language extends Component {
static navigationOptions = () => ({
...BlueNavigationStyle(),
title: loc.settings.language,
});
constructor(props) {
super(props);
this.state = {
isLoading: true,
language: loc.getLanguage(),
availableLanguages: [
{ label: 'English', value: 'en' },
{ label: 'Česky (CZ)', value: 'cs_cz' },
2019-02-19 22:07:47 +01:00
{ label: 'Chinese (ZH)', value: 'zh_cn' },
{ label: 'Croatian (HR)', value: 'hr_hr' },
{ label: 'Danish (DK)', value: 'da_dk' },
2019-03-09 20:08:47 +01:00
{ label: 'Norsk (NB)', value: 'nb_no' },
{ label: 'Deutsch (DE)', value: 'de_de' },
{ label: 'Español (ES)', value: 'es' },
2019-03-14 11:53:53 +01:00
{ label: 'Italiano (IT)', value: 'it' },
2019-03-15 00:05:44 +01:00
{ label: 'Suomi (FI)', value: 'fi_fi' },
2019-01-06 17:10:25 +01:00
{ label: 'Français (FR)', value: 'fr_fr' },
2019-02-14 00:20:10 +01:00
{ label: 'Indonesia (ID)', value: 'id_id' },
2019-06-19 22:45:33 +02:00
{ label: 'Magyar (HU)', value: 'hu_hu' },
2019-01-10 06:11:39 +01:00
{ label: '日本語 (JP)', value: 'jp_jp' },
{ label: 'Nederlands (NL)', value: 'nl_nl' },
{ label: 'Portuguese (BR)', value: 'pt_br' },
{ label: 'Portuguese (PT)', value: 'pt_pt' },
{ label: 'Русский', value: 'ru' },
2019-03-19 09:44:42 +01:00
{ label: 'Svenska (SE)', value: 'sv_se' },
{ label: 'Thai (TH)', value: 'th_th' },
{ label: 'Українська', value: 'ua' },
2019-03-09 01:23:53 +01:00
{ label: 'Ελληνικά (EL)', value: 'el' },
2019-03-16 13:53:31 +01:00
{ label: 'Türkçe (TR)', value: 'tr_tr' },
],
};
}
async componentDidMount() {
this.setState({
isLoading: false,
});
}
renderItem = ({ item }) => {
return (
<TouchableOpacity
onPress={() => {
console.log('setLanguage', item.value);
loc.saveLanguage(item.value);
return this.setState({ language: item.value });
}}
>
<BlueListItem
title={item.label}
{...(this.state.language === item.value
? {
rightIcon: <Icon name="check" type="font-awesome" color="#0c2550" />,
}
: { hideChevron: true })}
/>
</TouchableOpacity>
);
};
render() {
if (this.state.isLoading) {
return <BlueLoading />;
}
return (
<SafeBlueArea forceInset={{ horizontal: 'always' }} style={{ flex: 1 }}>
<FlatList
style={{ flex: 1 }}
keyExtractor={(_item, index) => `${index}`}
data={this.state.availableLanguages}
extraData={this.state.availableLanguages}
renderItem={this.renderItem}
/>
<BlueCard>
<BlueText>When selecting a new language, restarting BlueWallet may be required for the change to take effect.</BlueText>
</BlueCard>
</SafeBlueArea>
);
}
}
Language.propTypes = {
navigation: PropTypes.shape({
navigate: PropTypes.func,
goBack: PropTypes.func,
}),
};