@@ -6,7 +6,6 @@ const repoRoot = path.join(__dirname, '../../');
66const localesDir = path . join ( repoRoot , 'src/Resources/Locales' ) ;
77const enUSFile = path . join ( localesDir , 'en_US.axaml' ) ;
88const outputFile = path . join ( repoRoot , 'TRANSLATION.md' ) ;
9- const readmeFile = path . join ( repoRoot , 'README.md' ) ;
109
1110const parser = new xml2js . Parser ( ) ;
1211
@@ -18,46 +17,36 @@ async function parseXml(filePath) {
1817async function calculateTranslationRate ( ) {
1918 const enUSData = await parseXml ( enUSFile ) ;
2019 const enUSKeys = new Set ( enUSData . ResourceDictionary [ 'x:String' ] . map ( item => item . $ [ 'x:Key' ] ) ) ;
21-
22- const translationRates = [ ] ;
23- const badges = [ ] ;
24-
2520 const files = ( await fs . readdir ( localesDir ) ) . filter ( file => file !== 'en_US.axaml' && file . endsWith ( '.axaml' ) ) ;
2621
27- // Add en_US badge first
28- badges . push ( `[](TRANSLATION.md)` ) ;
22+ const lines = [ ] ;
23+
24+ lines . push ( '# Translation Status' ) ;
25+ lines . push ( 'This document shows the translation status of each locale file in the repository.' ) ;
26+ lines . push ( `## Details` ) ;
27+ lines . push ( `### ` ) ;
2928
3029 for ( const file of files ) {
30+ const locale = file . replace ( '.axaml' , '' ) . replace ( '_' , '__' ) ;
3131 const filePath = path . join ( localesDir , file ) ;
3232 const localeData = await parseXml ( filePath ) ;
3333 const localeKeys = new Set ( localeData . ResourceDictionary [ 'x:String' ] . map ( item => item . $ [ 'x:Key' ] ) ) ;
34-
3534 const missingKeys = [ ...enUSKeys ] . filter ( key => ! localeKeys . has ( key ) ) ;
36- const translationRate = ( ( enUSKeys . size - missingKeys . length ) / enUSKeys . size ) * 100 ;
3735
38- translationRates . push ( `### ${ file } : ${ translationRate . toFixed ( 2 ) } %\n` ) ;
39- translationRates . push ( `<details>\n<summary>Missing Keys</summary>\n\n${ missingKeys . map ( key => `- ${ key } ` ) . join ( '\n' ) } \n\n</details>` ) ;
36+ if ( missingKeys . length > 0 ) {
37+ const progress = ( ( enUSKeys . size - missingKeys . length ) / enUSKeys . size ) * 100 ;
38+ const badgeColor = progress >= 75 ? 'yellow' : 'red' ;
4039
41- // Add badges
42- const locale = file . replace ( '.axaml' , '' ) . replace ( '_' , '__' ) ;
43- if ( translationRate === 100 ) {
44- badges . push ( `[](TRANSLATION.md)` ) ;
40+ lines . push ( `###  } %25-${ badgeColor } )` ) ;
41+ lines . push ( `<details>\n<summary>Missing keys in ${ file } </summary>\n\n${ missingKeys . map ( key => `- ${ key } ` ) . join ( '\n' ) } \n\n</details>` )
4542 } else {
46- const badgeColor = translationRate >= 75 ? 'yellow' : 'red' ;
47- badges . push ( `[ } %25-${ badgeColor } )](TRANSLATION.md)` ) ;
48- }
43+ lines . push ( `### ` ) ;
44+ }
4945 }
5046
51- console . log ( translationRates . join ( '\n\n' ) ) ;
52-
53- await fs . writeFile ( outputFile , translationRates . join ( '\n\n' ) + '\n' , 'utf8' ) ;
54-
55- // Update README.md
56- let readmeContent = await fs . readFile ( readmeFile , 'utf8' ) ;
57- const badgeSection = `## Translation Status\n\n${ badges . join ( ' ' ) } ` ;
58- console . log ( badgeSection ) ;
59- readmeContent = readmeContent . replace ( / # # T r a n s l a t i o n S t a t u s \n \n .* \n \n / , badgeSection + '\n\n' ) ;
60- await fs . writeFile ( readmeFile , readmeContent , 'utf8' ) ;
47+ const content = lines . join ( '\n\n' ) ;
48+ console . log ( content ) ;
49+ await fs . writeFile ( outputFile , content , 'utf8' ) ;
6150}
6251
6352calculateTranslationRate ( ) . catch ( err => console . error ( err ) ) ;
0 commit comments