aboutsummaryrefslogtreecommitdiffstats
path: root/packages/main/src/i18n/loadLocalization.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/main/src/i18n/loadLocalization.ts')
-rw-r--r--packages/main/src/i18n/loadLocalization.ts23
1 files changed, 20 insertions, 3 deletions
diff --git a/packages/main/src/i18n/loadLocalization.ts b/packages/main/src/i18n/loadLocalization.ts
index 1408a30..ec3cf84 100644
--- a/packages/main/src/i18n/loadLocalization.ts
+++ b/packages/main/src/i18n/loadLocalization.ts
@@ -18,16 +18,22 @@
18 * SPDX-License-Identifier: AGPL-3.0-only 18 * SPDX-License-Identifier: AGPL-3.0-only
19 */ 19 */
20 20
21import { fallbackLng } from '@sophie/shared';
21import i18next from 'i18next'; 22import i18next from 'i18next';
23import { autorun } from 'mobx';
24import { addDisposer } from 'mobx-state-tree';
22 25
23import type Resources from '../infrastructure/resources/Resources'; 26import type Resources from '../infrastructure/resources/Resources';
24import type MainStore from '../stores/MainStore'; 27import type MainStore from '../stores/MainStore';
28import { getLogger } from '../utils/log';
25 29
26import I18nStore from './I18nStore'; 30import I18nStore from './I18nStore';
27import RepositoryBasedI18nBackend from './RepositoryBasedI18nBackend'; 31import RepositoryBasedI18nBackend from './RepositoryBasedI18nBackend';
28import i18nLog from './i18nLog'; 32import i18nLog from './i18nLog';
29import LocalizationFiles from './impl/LocaltizationFiles'; 33import LocalizationFiles from './impl/LocaltizationFiles';
30 34
35const log = getLogger('loadLocationzation');
36
31export default async function loadLocalization( 37export default async function loadLocalization(
32 store: MainStore, 38 store: MainStore,
33 resources: Resources, 39 resources: Resources,
@@ -37,14 +43,25 @@ export default async function loadLocalization(
37 const backend = new RepositoryBasedI18nBackend(repository, devMode); 43 const backend = new RepositoryBasedI18nBackend(repository, devMode);
38 const i18n = i18next 44 const i18n = i18next
39 .createInstance({ 45 .createInstance({
40 lng: 'en', 46 lng: store.shared.language,
41 fallbackLng: ['en'], 47 fallbackLng,
42 debug: devMode, 48 debug: devMode,
43 saveMissing: devMode, 49 saveMissing: devMode,
44 }) 50 })
45 .use(backend) 51 .use(backend)
46 .use(i18nLog); 52 .use(i18nLog);
47 await i18n.init();
48 const i18nStore = new I18nStore(i18n); 53 const i18nStore = new I18nStore(i18n);
49 store.setI18n(i18nStore); 54 store.setI18n(i18nStore);
55 await i18n.init();
56 const disposeChangeLanguage = autorun(() => {
57 const {
58 shared: { language },
59 } = store;
60 if (i18n.language !== language) {
61 i18n.changeLanguage(language).catch((error) => {
62 log.error('Failed to change language', error);
63 });
64 }
65 });
66 addDisposer(store, disposeChangeLanguage);
50} 67}