@@ -6,7 +6,6 @@ const repoRoot = path.join(__dirname, '../../');
6
6
const localesDir = path . join ( repoRoot , 'src/Resources/Locales' ) ;
7
7
const enUSFile = path . join ( localesDir , 'en_US.axaml' ) ;
8
8
const outputFile = path . join ( repoRoot , 'TRANSLATION.md' ) ;
9
- const readmeFile = path . join ( repoRoot , 'README.md' ) ;
10
9
11
10
const parser = new xml2js . Parser ( ) ;
12
11
@@ -18,46 +17,36 @@ async function parseXml(filePath) {
18
17
async function calculateTranslationRate ( ) {
19
18
const enUSData = await parseXml ( enUSFile ) ;
20
19
const enUSKeys = new Set ( enUSData . ResourceDictionary [ 'x:String' ] . map ( item => item . $ [ 'x:Key' ] ) ) ;
21
-
22
- const translationRates = [ ] ;
23
- const badges = [ ] ;
24
-
25
20
const files = ( await fs . readdir ( localesDir ) ) . filter ( file => file !== 'en_US.axaml' && file . endsWith ( '.axaml' ) ) ;
26
21
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 ( `### ` ) ;
29
28
30
29
for ( const file of files ) {
30
+ const locale = file . replace ( '.axaml' , '' ) . replace ( '_' , '__' ) ;
31
31
const filePath = path . join ( localesDir , file ) ;
32
32
const localeData = await parseXml ( filePath ) ;
33
33
const localeKeys = new Set ( localeData . ResourceDictionary [ 'x:String' ] . map ( item => item . $ [ 'x:Key' ] ) ) ;
34
-
35
34
const missingKeys = [ ...enUSKeys ] . filter ( key => ! localeKeys . has ( key ) ) ;
36
- const translationRate = ( ( enUSKeys . size - missingKeys . length ) / enUSKeys . size ) * 100 ;
37
35
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' ;
40
39
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>` )
45
42
} else {
46
- const badgeColor = translationRate >= 75 ? 'yellow' : 'red' ;
47
- badges . push ( `[ } %25-${ badgeColor } )](TRANSLATION.md)` ) ;
48
- }
43
+ lines . push ( `### ` ) ;
44
+ }
49
45
}
50
46
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' ) ;
61
50
}
62
51
63
52
calculateTranslationRate ( ) . catch ( err => console . error ( err ) ) ;
0 commit comments