File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 ;
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import {I18nManager} from 'react-native';
22import Onyx from 'react-native-onyx' ;
33import intlPolyfill from '@libs/IntlPolyfill' ;
44import { setDeviceID } from '@userActions/Device' ;
5+ import initLocale from '@userActions/Locale' ;
56import initOnyxDerivedValues from '@userActions/OnyxDerived' ;
67import CONST from '@src/CONST' ;
78import 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 ( ) ;
You can’t perform that action at this time.
0 commit comments