Skip to content

Commit

Permalink
Merge pull request #3638 from Expensify/Rory-FixLanguageSelector
Browse files Browse the repository at this point in the history
Fix language selector
  • Loading branch information
robertjchen committed Jun 17, 2021
2 parents 7b607e3 + 79ff2f7 commit dbe484c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 7 deletions.
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);

0 comments on commit dbe484c

Please sign in to comment.