File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ const OUTPUT = path.resolve('src/helpers/i18n/i18n.gen.ts');
66
77const resources : Record < string , Record < string , string > > = { } ;
88const namespaces = new Set < string > ( ) ;
9+ const imports : string [ ] = [ ] ;
910
1011for ( const ns of fs . readdirSync ( LOCALES_DIR ) ) {
1112 const nsPath = path . join ( LOCALES_DIR , ns ) ;
@@ -17,13 +18,17 @@ for (const ns of fs.readdirSync(LOCALES_DIR)) {
1718 if ( ! file . endsWith ( '.ts' ) ) continue ;
1819
1920 const lang = file . replace ( '.ts' , '' ) ;
21+ const varName = `${ lang . replace ( / [ ^ a - z A - Z 0 - 9 ] / g, '' ) } _${ ns } ` ;
2022 resources [ lang ] ??= { } ;
21- resources [ lang ] [ ns ] = `() => import('../../locales/${ ns } /${ lang } ')` ;
23+ resources [ lang ] [ ns ] = varName ;
24+ imports . push ( `import ${ varName } from '../../locales/${ ns } /${ lang } ';` ) ;
2225 }
2326}
2427
2528const content = `
2629/* AUTO-GENERATED — DO NOT EDIT */
30+ ${ imports . join ( '\n' ) }
31+
2732export const namespaces = ${ JSON . stringify ( [ ...namespaces ] ) }
2833
2934export const resources = {
@@ -37,7 +42,8 @@ ${Object.entries(nss)
3742 },` ,
3843 )
3944 . join ( '\n' ) }
45+
4046}
4147` ;
4248
43- fs . writeFileSync ( OUTPUT , content . trim ( ) ) ;
49+ fs . writeFileSync ( OUTPUT , content . trim ( ) ) ;
Original file line number Diff line number Diff line change 11/* AUTO-GENERATED — DO NOT EDIT */
2+ import viVN_common from '../../locales/common/vi-VN' ;
3+ import enUS_common from '../../locales/common/en-US' ;
4+ import viVN_exception from '../../locales/exception/vi-VN' ;
5+ import enUS_exception from '../../locales/exception/en-US' ;
6+
27export const namespaces = [ "common" , "exception" ]
38
49export const resources = {
510
6- 'en-US ' : {
7- common : ( ) => import ( '../../locales/common/en-US' ) ,
8- exception : ( ) => import ( '../../locales/exception/en-US' ) ,
11+ 'vi-VN ' : {
12+ common : viVN_common ,
13+ exception : viVN_exception ,
914 } ,
1015
11- 'vi-VN ' : {
12- common : ( ) => import ( '../../locales/common/vi-VN' ) ,
13- exception : ( ) => import ( '../../locales/exception/vi-VN' ) ,
16+ 'en-US ' : {
17+ common : enUS_common ,
18+ exception : enUS_exception ,
1419 } ,
20+
1521}
Original file line number Diff line number Diff line change @@ -12,7 +12,7 @@ for (const lang in resources) {
1212 resolved [ l ] = { } ;
1313 for ( const ns in resources [ l ] ) {
1414 const n = ns as Ns ;
15- resolved [ l ] [ n ] = ( await resources [ l ] [ n ] ( ) ) . default ;
15+ resolved [ l ] [ n ] = resources [ l ] [ n ] ;
1616 }
1717}
1818
You can’t perform that action at this time.
0 commit comments