@@ -6,6 +6,7 @@ const scriptDir = path.dirname(fileURLToPath(import.meta.url));
66const projectRoot = path . resolve ( scriptDir , '..' ) ;
77const srcDir = path . join ( projectRoot , 'src' ) ;
88const localesDir = path . join ( srcDir , 'i18n' , 'locales' ) ;
9+ const DEFAULT_LOCALE = 'zh' ;
910
1011function readJson ( filePath ) {
1112 return JSON . parse ( fs . readFileSync ( filePath , 'utf8' ) ) ;
@@ -76,11 +77,16 @@ for (const file of files) {
7677 }
7778}
7879
79- const missingByLocale = { } ;
80+ const errorMissingByLocale = { } ;
81+ const warningMissingByLocale = { } ;
8082for ( const [ locale , keys ] of Object . entries ( locales ) ) {
8183 const missing = Array . from ( usedKeys ) . filter ( key => ! keys . has ( key ) ) . sort ( ) ;
8284 if ( missing . length > 0 ) {
83- missingByLocale [ locale ] = missing ;
85+ if ( locale === DEFAULT_LOCALE ) {
86+ errorMissingByLocale [ locale ] = missing ;
87+ } else {
88+ warningMissingByLocale [ locale ] = missing ;
89+ }
8490 }
8591}
8692
@@ -90,13 +96,24 @@ if (dynamicKeys.size > 0) {
9096 console . log ( `Dynamic template keys skipped: ${ dynamicKeys . size } ` ) ;
9197}
9298
93- if ( Object . keys ( missingByLocale ) . length === 0 ) {
99+ if ( Object . keys ( errorMissingByLocale ) . length === 0 && Object . keys ( warningMissingByLocale ) . length === 0 ) {
94100 console . log ( 'No missing keys detected for string-literal usages.' ) ;
95101 process . exit ( 0 ) ;
96102}
97103
98- for ( const [ locale , missing ] of Object . entries ( missingByLocale ) ) {
99- console . log ( `\nMissing in ${ locale } (${ missing . length } ):` ) ;
104+ for ( const [ locale , missing ] of Object . entries ( warningMissingByLocale ) ) {
105+ console . log ( `\nMissing in ${ locale } (${ missing . length } ) [fallback -> ${ DEFAULT_LOCALE } ]:` ) ;
106+ for ( const key of missing ) {
107+ console . log ( ` - ${ key } ` ) ;
108+ }
109+ }
110+
111+ if ( Object . keys ( errorMissingByLocale ) . length === 0 ) {
112+ process . exit ( 0 ) ;
113+ }
114+
115+ for ( const [ locale , missing ] of Object . entries ( errorMissingByLocale ) ) {
116+ console . log ( `\nMissing in ${ locale } (${ missing . length } ) [required]:` ) ;
100117 for ( const key of missing ) {
101118 console . log ( ` - ${ key } ` ) ;
102119 }
0 commit comments