-
Notifications
You must be signed in to change notification settings - Fork 3
/
LanguageSelector.tsx
77 lines (72 loc) · 1.79 KB
/
LanguageSelector.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React from 'react';
import {
StyleSheet,
Text,
View,
TouchableOpacity,
Dimensions,
} from 'react-native';
import {useTranslation} from 'react-i18next';
const {width} = Dimensions.get('window');
const LANGS = [
{lngCode: 'en', label: 'English'},
{lngCode: 'hi', label: 'हिन्दी'},
];
const LanguageSelector = () => {
const {t, i18n} = useTranslation();
const selectedLngCode = i18n.language;
const setLng = (lngCode: string) => i18n.changeLanguage(lngCode);
return (
<View style={styles.container}>
<View style={styles.titleContainer}>
<Text style={styles.select}>{t('languageSelector:selectLng')}</Text>
</View>
{LANGS.map((l) => {
const selected = l.lngCode === selectedLngCode;
return (
<TouchableOpacity
onPress={() => setLng(l.lngCode)}
key={l.lngCode}
disabled={selected}>
<View style={[styles.row, selected ? styles.selectedRow : {}]}>
<Text style={[selected ? styles.selectedText : styles.text]}>
{l.label}
</Text>
{selected && <Text>👍</Text>}
</View>
</TouchableOpacity>
);
})}
</View>
);
};
export default LanguageSelector;
const styles = StyleSheet.create({
container: {
padding: 10,
backgroundColor: 'rgb(231, 232, 235)',
width: width * 0.8,
},
titleContainer: {
alignItems: 'center',
paddingBottom: 20,
},
select: {
fontSize: 20,
},
row: {
flexDirection: 'row',
justifyContent: 'space-between',
paddingHorizontal: 10,
paddingVertical: 5,
},
selectedRow: {
backgroundColor: 'rgb(45, 45, 45)',
},
selectedText: {
color: 'rgb(231, 232, 235)',
},
text: {
color: 'rgb(45, 45, 45)',
},
});