Skip to content

Commit 20feabf

Browse files
committed
fix(i18n): merge hmr locale injection instead of discarding
1 parent f44e113 commit 20feabf

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/stores/i18n.store.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ export const useI18nStore = defineStore('i18n', () => {
3232
return result;
3333
};
3434

35-
const addLocale = (_locale: Locale, _lang = lang.value) => {
36-
locales.value[_lang] = _locale;
35+
const addLocale = (_locale: Locale, _lang = lang.value, merge = false) => {
36+
locales.value[_lang] = merge ? { ...locales.value[_lang], ..._locale } : _locale;
3737
return locales.value;
3838
};
3939

src/utils/i18n.utils.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const initLocalI18n = () => {
1313
console.info('Listening to i18n HMR changes');
1414
import.meta.hot.send('fetch:i18n');
1515
import.meta.hot.on('update:i18n', (data: { lang: string; locale: Locale }[]) => {
16-
data?.forEach(({ lang, locale }) => store.addLocale(locale, lang));
16+
data?.forEach(({ lang, locale }) => store.addLocale(locale, lang, true));
1717
});
1818
} else if (!store.locales?.[store.lang]) {
1919
promise = fetch(new URL(`${router.baseUrl ?? './'}_locales/${store.lang}/messages.json`, new URL(import.meta.url).origin))

0 commit comments

Comments
 (0)