File tree 1 file changed +8
-4
lines changed
1 file changed +8
-4
lines changed Original file line number Diff line number Diff line change @@ -3,15 +3,19 @@ import { useI18n as chromeUseI18n } from '@dvcol/web-extension-utils/lib/chrome/
3
3
import type { Locale } from '~/models/i18n.model' ;
4
4
5
5
import { useI18nStore } from '~/stores/i18n.store' ;
6
+ import { useRouterStore } from '~/stores/router.store' ;
6
7
7
8
export const useI18n = ( ...roots : string [ ] ) : ReturnType < typeof chromeUseI18n > => {
8
9
if ( ! chrome ?. i18n ) {
9
10
const store = useI18nStore ( ) ;
11
+ const router = useRouterStore ( ) ;
10
12
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
+ }
15
19
16
20
return ( value , modules ) => store . i18n ( value , ...( modules ?. length ? modules : roots ) ) ;
17
21
}
You can’t perform that action at this time.
0 commit comments