Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix language selector #3638

Merged
merged 3 commits into from Jun 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libs/OptionsListUtils.js
Expand Up @@ -162,7 +162,7 @@ Onyx.connect({

Onyx.connect({
key: ONYXKEYS.PREFERRED_LOCALE,
callback: val => preferredLocale = val || 'en',
callback: val => preferredLocale = val || CONST.DEFAULT_LOCALE,
});

/**
Expand Down
9 changes: 8 additions & 1 deletion src/libs/actions/App.js
Expand Up @@ -8,7 +8,14 @@ function setCurrentURL(url) {
Onyx.set(ONYXKEYS.CURRENT_URL, url);
}

/**
* @param {String} locale
*/
function setLocale(locale) {
Onyx.set(ONYXKEYS.PREFERRED_LOCALE, locale);
}

export {
// eslint-disable-next-line import/prefer-default-export
setCurrentURL,
setLocale,
};
19 changes: 14 additions & 5 deletions src/pages/settings/PreferencesPage.js
@@ -1,6 +1,6 @@
import React from 'react';
import {View} from 'react-native';
import Onyx, {withOnyx} from 'react-native-onyx';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';

import HeaderWithCloseButton from '../../components/HeaderWithCloseButton';
Expand All @@ -12,6 +12,7 @@ import Text from '../../components/Text';
import NameValuePair from '../../libs/actions/NameValuePair';
import CONST from '../../CONST';
import {setExpensifyNewsStatus} from '../../libs/actions/User';
import {setLocale} from '../../libs/actions/App';
import ScreenWrapper from '../../components/ScreenWrapper';
import Switch from '../../components/Switch';
import Picker from '../../components/Picker';
Expand All @@ -28,15 +29,16 @@ const propTypes = {
expensifyNewsStatus: PropTypes.bool,
}),

...withLocalizePropTypes,
/** Indicates which locale the user currently has selected */
preferredLocale: PropTypes.string,

// Indicates which locale the user currently has selected
preferredLocale: PropTypes.string.isRequired,
...withLocalizePropTypes,
};

const defaultProps = {
priorityMode: CONST.PRIORITY_MODE.DEFAULT,
user: {},
preferredLocale: CONST.DEFAULT_LOCALE,
};

const PreferencesPage = ({
Expand Down Expand Up @@ -112,7 +114,11 @@ const PreferencesPage = ({
</Text>
<View style={[styles.mb2]}>
<Picker
onChange={locale => Onyx.merge(ONYXKEYS.PREFERRED_LOCALE, locale)}
onChange={(locale) => {
if (locale !== preferredLocale) {
setLocale(locale);
}
}}
items={Object.values(localesToLanguages)}
value={preferredLocale}
/>
Expand All @@ -136,5 +142,8 @@ export default compose(
user: {
key: ONYXKEYS.USER,
},
preferredLocale: {
key: ONYXKEYS.PREFERRED_LOCALE,
},
}),
)(PreferencesPage);