Skip to content

Commit 02036af

Browse files
committed
fix(web): fix local url fetching
1 parent dbe5684 commit 02036af

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/utils/i18n.utils.ts

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@ import { useI18n as chromeUseI18n } from '@dvcol/web-extension-utils/lib/chrome/
33
import type { Locale } from '~/models/i18n.model';
44

55
import { useI18nStore } from '~/stores/i18n.store';
6+
import { useRouterStore } from '~/stores/router.store';
67

78
export const useI18n = (...roots: string[]): ReturnType<typeof chromeUseI18n> => {
89
if (!chrome?.i18n) {
910
const store = useI18nStore();
11+
const router = useRouterStore();
1012

11-
fetch(new URL(`./_locales/${store.lang}/messages.json`, new URL(import.meta.url).origin))
12-
.then(r => r.json())
13-
.then((locale: Locale) => store.addLocale(locale))
14-
.catch(err => console.error(`Failed to fetch locale '${store.lang}'`, err));
13+
if (!store.locales?.[store.lang]) {
14+
fetch(new URL(`${router.baseName ?? '.'}/_locales/${store.lang}/messages.json`, new URL(import.meta.url).origin))
15+
.then(r => r.json())
16+
.then((locale: Locale) => store.addLocale(locale))
17+
.catch(err => console.error(`Failed to fetch locale '${store.lang}'`, err));
18+
}
1519

1620
return (value, modules) => store.i18n(value, ...(modules?.length ? modules : roots));
1721
}

0 commit comments

Comments
 (0)