Browse Source

Improve local management

This allows fast refresh when working on locales
Arnaud Vergnet 1 year ago
parent
commit
3de49732b9
3 changed files with 19 additions and 26 deletions
  1. 2
    2
      App.js
  2. 0
    24
      src/managers/LocaleManager.js
  3. 17
    0
      src/utils/Locales.js

+ 2
- 2
App.js View File

@@ -7,7 +7,6 @@ import {Provider as PaperProvider} from 'react-native-paper';
7 7
 import {setSafeBounceHeight} from 'react-navigation-collapsible';
8 8
 import SplashScreen from 'react-native-splash-screen';
9 9
 import {OverflowMenuProvider} from 'react-navigation-header-buttons';
10
-import LocaleManager from './src/managers/LocaleManager';
11 10
 import AsyncStorageManager from './src/managers/AsyncStorageManager';
12 11
 import CustomIntroSlider from './src/components/Overrides/CustomIntroSlider';
13 12
 import type {CustomThemeType} from './src/managers/ThemeManager';
@@ -19,6 +18,7 @@ import ConnectionManager from './src/managers/ConnectionManager';
19 18
 import type {ParsedUrlDataType} from './src/utils/URLHandler';
20 19
 import URLHandler from './src/utils/URLHandler';
21 20
 import {setupStatusBar} from './src/utils/Utils';
21
+import initLocales from './src/utils/Locales';
22 22
 
23 23
 // Native optimizations https://reactnavigation.org/docs/react-native-screens
24 24
 // Crashes app when navigating away from webview on android 9+
@@ -56,7 +56,7 @@ export default class App extends React.Component<null, StateType> {
56 56
       showAprilFools: false,
57 57
       currentTheme: null,
58 58
     };
59
-    LocaleManager.initTranslations();
59
+    initLocales();
60 60
     this.navigatorRef = React.createRef();
61 61
     this.defaultHomeRoute = null;
62 62
     this.defaultHomeData = {};

+ 0
- 24
src/managers/LocaleManager.js View File

@@ -1,24 +0,0 @@
1
-// @flow
2
-
3
-import i18n from 'i18n-js';
4
-import * as RNLocalize from 'react-native-localize';
5
-
6
-import en from '../../locales/en.json';
7
-import fr from '../../locales/fr.json';
8
-
9
-/**
10
- * Static class used to manage locales
11
- */
12
-export default class LocaleManager {
13
-  /**
14
-   * Initialize translations using language files
15
-   */
16
-  static initTranslations() {
17
-    i18n.fallbacks = true;
18
-    i18n.translations = {fr, en};
19
-    i18n.locale = RNLocalize.findBestAvailableLanguage([
20
-      'en',
21
-      'fr',
22
-    ]).languageTag;
23
-  }
24
-}

+ 17
- 0
src/utils/Locales.js View File

@@ -0,0 +1,17 @@
1
+// @flow
2
+
3
+import i18n from 'i18n-js';
4
+import * as RNLocalize from 'react-native-localize';
5
+
6
+import en from '../../locales/en.json';
7
+import fr from '../../locales/fr.json';
8
+
9
+const initLocales = () => {
10
+  i18n.fallbacks = true;
11
+  i18n.translations = {fr, en};
12
+  i18n.locale = RNLocalize.findBestAvailableLanguage([
13
+    'en',
14
+    'fr',
15
+  ]).languageTag;
16
+}
17
+export default initLocales;

Loading…
Cancel
Save