Skip to content

Commit cbdf323

Browse files
authored
Merge pull request Expensify#64378 from Expensify/jules-fixLazyLoadTranslations
Fix lazy loading translations issue with auth page
2 parents 9f6e7a5 + 60dcbee commit cbdf323

2 files changed

Lines changed: 25 additions & 0 deletions

File tree

src/libs/actions/Locale.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import Onyx from 'react-native-onyx';
2+
import {getDevicePreferredLocale} from '@libs/Localize';
3+
import TranslationStore from '@src/languages/TranslationStore';
4+
import ONYXKEYS from '@src/ONYXKEYS';
5+
6+
/* There are scenarios where locale is not loaded and we start to render UI which results in rendering translations keys instead of real translations.
7+
* E.g. when we transition from OldDot to NewDot during sign-out.
8+
* This function is used to ensure that the locale is loaded before we start to render UI. Once we load initial locale we can remove listener.
9+
*/
10+
function init() {
11+
const connection = Onyx.connect({
12+
key: ONYXKEYS.NVP_PREFERRED_LOCALE,
13+
initWithStoredValues: true,
14+
callback: (locale) => {
15+
Onyx.disconnect(connection);
16+
TranslationStore.load(locale ?? getDevicePreferredLocale());
17+
},
18+
});
19+
}
20+
21+
export default init;

src/setup/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import {I18nManager} from 'react-native';
22
import Onyx from 'react-native-onyx';
33
import intlPolyfill from '@libs/IntlPolyfill';
44
import {setDeviceID} from '@userActions/Device';
5+
import initLocale from '@userActions/Locale';
56
import initOnyxDerivedValues from '@userActions/OnyxDerived';
67
import CONST from '@src/CONST';
78
import ONYXKEYS from '@src/ONYXKEYS';
@@ -52,6 +53,9 @@ export default function () {
5253
skippableCollectionMemberIDs: CONST.SKIPPABLE_COLLECTION_MEMBER_IDS,
5354
});
5455

56+
// Init locale early to avoid rendering translations keys instead of real translations
57+
initLocale();
58+
5559
initOnyxDerivedValues();
5660

5761
setDeviceID();

0 commit comments

Comments
 (0)