Skip to content

Commit

Permalink
Merge pull request #5019 from Expensify/monil-updateLocale
Browse files Browse the repository at this point in the history
Remember preferred locale on signup/login
  • Loading branch information
Luke9389 authored Sep 9, 2021
2 parents 1089144 + 72ec25d commit f8c6120
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/libs/Navigation/AppNavigator/AuthScreens.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ import WorkspaceSettingsDrawerNavigator from './WorkspaceSettingsDrawerNavigator
import spacing from '../../../styles/utilities/spacing';
import CardOverlay from '../../../components/CardOverlay';
import defaultScreenOptions from './defaultScreenOptions';
import * as API from '../../API';
import {setLocale} from '../../actions/App';

Onyx.connect({
key: ONYXKEYS.MY_PERSONAL_DETAILS,
Expand All @@ -88,6 +90,12 @@ Onyx.connect({
},
});

let currentPreferredLocale;
Onyx.connect({
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
callback: val => currentPreferredLocale = val || CONST.DEFAULT_LOCALE,
});

const RootStack = createCustomModalStackNavigator();

// We want to delay the re-rendering for components(e.g. ReportActionCompose)
Expand Down Expand Up @@ -159,7 +167,19 @@ class AuthScreens extends React.Component {

// Fetch some data we need on initialization
NameValuePair.get(CONST.NVP.PRIORITY_MODE, ONYXKEYS.NVP_PRIORITY_MODE, 'default');
NameValuePair.get(CONST.NVP.PREFERRED_LOCALE, ONYXKEYS.NVP_PREFERRED_LOCALE, 'en');

API.Get({
returnValueList: 'nameValuePairs',
nvpNames: ONYXKEYS.NVP_PREFERRED_LOCALE,
}).then((response) => {
const preferredLocale = response.nameValuePairs.preferredLocale || CONST.DEFAULT_LOCALE;
if ((currentPreferredLocale !== CONST.DEFAULT_LOCALE) && (preferredLocale !== currentPreferredLocale)) {
setLocale(currentPreferredLocale);
} else {
Onyx.set(ONYXKEYS.NVP_PREFERRED_LOCALE, preferredLocale);
}
});

PersonalDetails.fetchPersonalDetails();
User.getUserDetails();
User.getBetas();
Expand Down

0 comments on commit f8c6120

Please sign in to comment.