Improve local management
This allows fast refresh when working on locales
This commit is contained in:
parent
c3d324549d
commit
3de49732b9
3 changed files with 19 additions and 26 deletions
4
App.js
4
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<null, StateType> {
|
|||
showAprilFools: false,
|
||||
currentTheme: null,
|
||||
};
|
||||
LocaleManager.initTranslations();
|
||||
initLocales();
|
||||
this.navigatorRef = React.createRef();
|
||||
this.defaultHomeRoute = null;
|
||||
this.defaultHomeData = {};
|
||||
|
|
|
@ -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
17
src/utils/Locales.js
Normal 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;
|
Loading…
Reference in a new issue