File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- import * as i18n from '@solid-primitives/i18n' ;
2- import { type Accessor , createResource } from 'solid-js' ;
3- import type { GlobalDictionary , RawGlobalDictionary } from '@/locales' ;
1+ import { flatten , translator } from '@solid-primitives/i18n' ;
2+ import type { Accessor } from 'solid-js' ;
3+ import type { RawGlobalDictionary } from '@/locales' ;
4+ import en from '@/locales/en' ;
45import zhCN from '@/locales/zh-CN' ;
56
6- async function fetchDictionary < T > ( locale : T ) : Promise < GlobalDictionary > {
7- const dict : RawGlobalDictionary = ( await import ( `@/locales/${ locale } ` ) ) . default ;
8- return i18n . flatten ( dict ) ;
9- }
10-
117export default function createGlobalTranslator < T extends string > ( currentLocale : Accessor < T > ) {
12- const [ dict ] = createResource ( currentLocale , fetchDictionary , { initialValue : i18n . flatten ( zhCN ) } ) ;
13- const t = i18n . translator ( dict ) ;
8+ const dictionary = ( ) => {
9+ let rawDictionary : RawGlobalDictionary ;
10+ switch ( currentLocale ( ) ) {
11+ case 'zh-CN' :
12+ rawDictionary = zhCN ;
13+ break ;
14+ case 'en' :
15+ rawDictionary = en ;
16+ break ;
17+ default :
18+ rawDictionary = zhCN ;
19+ }
20+ return flatten ( rawDictionary ) ;
21+ } ;
22+ const t = translator ( dictionary ) ;
1423 return t ;
1524}
You can’t perform that action at this time.
0 commit comments