-
Notifications
You must be signed in to change notification settings - Fork 2.9k
/
LanguagePage.js
49 lines (43 loc) · 1.71 KB
/
LanguagePage.js
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
import PropTypes from 'prop-types';
import React from 'react';
import _ from 'underscore';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import withLocalize, {withLocalizePropTypes} from '@components/withLocalize';
import Navigation from '@libs/Navigation/Navigation';
import * as App from '@userActions/App';
import CONST from '@src/CONST';
import ROUTES from '@src/ROUTES';
const propTypes = {
...withLocalizePropTypes,
/** The preferred language of the App */
preferredLocale: PropTypes.string.isRequired,
};
function LanguagePage(props) {
const localesToLanguages = _.map(CONST.LANGUAGES, (language) => ({
value: language,
text: props.translate(`languagePage.languages.${language}.label`),
keyForList: language,
isSelected: props.preferredLocale === language,
}));
return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={LanguagePage.displayName}
>
<HeaderWithBackButton
title={props.translate('languagePage.language')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_PREFERENCES)}
/>
<SelectionList
sections={[{data: localesToLanguages}]}
onSelectRow={(language) => App.setLocaleAndNavigate(language.value)}
initiallyFocusedOptionKey={_.find(localesToLanguages, (locale) => locale.isSelected).keyForList}
/>
</ScreenWrapper>
);
}
LanguagePage.displayName = 'LanguagePage';
LanguagePage.propTypes = propTypes;
export default withLocalize(LanguagePage);