Improve local management

This allows fast refresh when working on locales
This commit is contained in:
Arnaud Vergnet 2020-09-10 18:51:34 +02:00
parent c3d324549d
commit 3de49732b9
3 changed files with 19 additions and 26 deletions

4
App.js
View file

@ -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<null, StateType> {
showAprilFools: false,
currentTheme: null,
};
LocaleManager.initTranslations();
initLocales();
this.navigatorRef = React.createRef();
this.defaultHomeRoute = null;
this.defaultHomeData = {};

View file

@ -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;
}
}

17
src/utils/Locales.js Normal file
View file

@ -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;