From 3de49732b9df8098a2109c0887937daf507d4834 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Thu, 10 Sep 2020 18:51:34 +0200 Subject: [PATCH] Improve local management This allows fast refresh when working on locales --- App.js | 4 ++-- src/managers/LocaleManager.js | 24 ------------------------ src/utils/Locales.js | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 26 deletions(-) delete mode 100644 src/managers/LocaleManager.js create mode 100644 src/utils/Locales.js diff --git a/App.js b/App.js index 9fb4c71..aba049b 100644 --- a/App.js +++ b/App.js @@ -7,7 +7,6 @@ import {Provider as PaperProvider} from 'react-native-paper'; import {setSafeBounceHeight} from 'react-navigation-collapsible'; import SplashScreen from 'react-native-splash-screen'; import {OverflowMenuProvider} from 'react-navigation-header-buttons'; -import LocaleManager from './src/managers/LocaleManager'; import AsyncStorageManager from './src/managers/AsyncStorageManager'; import CustomIntroSlider from './src/components/Overrides/CustomIntroSlider'; import type {CustomThemeType} from './src/managers/ThemeManager'; @@ -19,6 +18,7 @@ import ConnectionManager from './src/managers/ConnectionManager'; import type {ParsedUrlDataType} from './src/utils/URLHandler'; import URLHandler from './src/utils/URLHandler'; import {setupStatusBar} from './src/utils/Utils'; +import initLocales from './src/utils/Locales'; // Native optimizations https://reactnavigation.org/docs/react-native-screens // Crashes app when navigating away from webview on android 9+ @@ -56,7 +56,7 @@ export default class App extends React.Component { showAprilFools: false, currentTheme: null, }; - LocaleManager.initTranslations(); + initLocales(); this.navigatorRef = React.createRef(); this.defaultHomeRoute = null; this.defaultHomeData = {}; diff --git a/src/managers/LocaleManager.js b/src/managers/LocaleManager.js deleted file mode 100644 index 72c677b..0000000 --- a/src/managers/LocaleManager.js +++ /dev/null @@ -1,24 +0,0 @@ -// @flow - -import i18n from 'i18n-js'; -import * as RNLocalize from 'react-native-localize'; - -import en from '../../locales/en.json'; -import fr from '../../locales/fr.json'; - -/** - * Static class used to manage locales - */ -export default class LocaleManager { - /** - * Initialize translations using language files - */ - static initTranslations() { - i18n.fallbacks = true; - i18n.translations = {fr, en}; - i18n.locale = RNLocalize.findBestAvailableLanguage([ - 'en', - 'fr', - ]).languageTag; - } -} diff --git a/src/utils/Locales.js b/src/utils/Locales.js new file mode 100644 index 0000000..0cf3db6 --- /dev/null +++ b/src/utils/Locales.js @@ -0,0 +1,17 @@ +// @flow + +import i18n from 'i18n-js'; +import * as RNLocalize from 'react-native-localize'; + +import en from '../../locales/en.json'; +import fr from '../../locales/fr.json'; + +const initLocales = () => { + i18n.fallbacks = true; + i18n.translations = {fr, en}; + i18n.locale = RNLocalize.findBestAvailableLanguage([ + 'en', + 'fr', + ]).languageTag; +} +export default initLocales;