diff options
author | Kristóf Marussy <kristof@marussy.com> | 2022-03-30 13:34:40 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2022-05-16 00:54:57 +0200 |
commit | 0f8c96d26a74865a35440338739de037bf984315 (patch) | |
tree | 77767c4107b72ee763115ddb4ecad64d898bdafd /packages/main/src/i18n | |
parent | feat(main): Add localization support (diff) | |
download | sophie-0f8c96d26a74865a35440338739de037bf984315.tar.gz sophie-0f8c96d26a74865a35440338739de037bf984315.tar.zst sophie-0f8c96d26a74865a35440338739de037bf984315.zip |
feat(main): Translation hot reloading during development
Signed-off-by: Kristóf Marussy <kristof@marussy.com>
Diffstat (limited to 'packages/main/src/i18n')
-rw-r--r-- | packages/main/src/i18n/I18nStore.ts | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/packages/main/src/i18n/I18nStore.ts b/packages/main/src/i18n/I18nStore.ts index d833e8a..c364f0e 100644 --- a/packages/main/src/i18n/I18nStore.ts +++ b/packages/main/src/i18n/I18nStore.ts | |||
@@ -82,7 +82,12 @@ export default class I18nStore { | |||
82 | }; | 82 | }; |
83 | 83 | ||
84 | const loadAsync = async () => { | 84 | const loadAsync = async () => { |
85 | await this.i18next.loadNamespaces([ns]); | 85 | try { |
86 | await this.i18next.loadNamespaces([ns]); | ||
87 | } catch (error) { | ||
88 | setImmediate(loaded); | ||
89 | throw error; | ||
90 | } | ||
86 | if (this.i18next.isInitialized) { | 91 | if (this.i18next.isInitialized) { |
87 | setImmediate(loaded); | 92 | setImmediate(loaded); |
88 | return; | 93 | return; |
@@ -98,7 +103,14 @@ export default class I18nStore { | |||
98 | 103 | ||
99 | loadAsync().catch((error) => { | 104 | loadAsync().catch((error) => { |
100 | log.error('Failed to load translations for namespace', ns, error); | 105 | log.error('Failed to load translations for namespace', ns, error); |
101 | setImmediate(loaded); | ||
102 | }); | 106 | }); |
103 | } | 107 | } |
108 | |||
109 | async reloadTranslations(): Promise<void> { | ||
110 | await this.i18next.reloadResources(); | ||
111 | setImmediate(() => { | ||
112 | this.languageChangedAtom.reportChanged(); | ||
113 | }); | ||
114 | log.debug('Reloaded translations'); | ||
115 | } | ||
104 | } | 116 | } |