From 39f4cd173287a3d531e6e3225009b5527f77e193 Mon Sep 17 00:00:00 2001 From: leo Date: Fri, 21 Mar 2025 10:54:47 +0800 Subject: [PATCH] ci: move all translation status to `TRANSLATION.md` and do not modify `README.md ` while checking localization Signed-off-by: leo --- README.md | 7 +-- TRANSLATION.md | 66 +++++++++-------------------- build/scripts/localization-check.js | 45 ++++++++------------ 3 files changed, 38 insertions(+), 80 deletions(-) diff --git a/README.md b/README.md index 00779cc7..d63886ed 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ * Supports SSH access with each remote * GIT commands with GUI * Clone/Fetch/Pull/Push... - * Merge/Rebase/Reset/Revert/Amend/Cherry-pick... + * Merge/Rebase/Reset/Revert/Cherry-pick... * Amend/Reword/Squash * Interactive rebase * Branches @@ -48,10 +48,7 @@ ## Translation Status -[![en_US](https://img.shields.io/badge/en__US-%E2%88%9A-brightgreen)](TRANSLATION.md) [![de__DE](https://img.shields.io/badge/de__DE-98.92%25-yellow)](TRANSLATION.md) [![es__ES](https://img.shields.io/badge/es__ES-99.87%25-yellow)](TRANSLATION.md) [![fr__FR](https://img.shields.io/badge/fr__FR-%E2%88%9A-brightgreen)](TRANSLATION.md) [![it__IT](https://img.shields.io/badge/it__IT-99.87%25-yellow)](TRANSLATION.md) [![pt__BR](https://img.shields.io/badge/pt__BR-91.12%25-yellow)](TRANSLATION.md) [![ru__RU](https://img.shields.io/badge/ru__RU-%E2%88%9A-brightgreen)](TRANSLATION.md) [![zh__CN](https://img.shields.io/badge/zh__CN-%E2%88%9A-brightgreen)](TRANSLATION.md) [![zh__TW](https://img.shields.io/badge/zh__TW-%E2%88%9A-brightgreen)](TRANSLATION.md) - -> [!NOTE] -> You can find the missing keys in [TRANSLATION.md](TRANSLATION.md) +You can find the current translation status in [TRANSLATION.md](TRANSLATION.md) ## How to Use diff --git a/TRANSLATION.md b/TRANSLATION.md index aa8da630..a96f0fc6 100644 --- a/TRANSLATION.md +++ b/TRANSLATION.md @@ -1,8 +1,15 @@ -### de_DE.axaml: 98.92% +# Translation Status +This document shows the translation status of each locale file in the repository. + +## Details + +### ![en_US](https://img.shields.io/badge/en__US-%E2%88%9A-brightgreen) + +### ![de__DE](https://img.shields.io/badge/de__DE-98.92%25-yellow)
-Missing Keys +Missing keys in de_DE.axaml - Text.BranchUpstreamInvalid - Text.Configure.CustomAction.WaitForExit @@ -15,41 +22,30 @@
-### es_ES.axaml: 99.87% - +### ![es__ES](https://img.shields.io/badge/es__ES-99.87%25-yellow)
-Missing Keys +Missing keys in es_ES.axaml - Text.Preferences.General.ShowTagsInGraph
-### fr_FR.axaml: 100.00% +### ![fr__FR](https://img.shields.io/badge/fr__FR-%E2%88%9A-brightgreen) +### ![it__IT](https://img.shields.io/badge/it__IT-99.87%25-yellow)
-Missing Keys - - - -
- -### it_IT.axaml: 99.87% - - -
-Missing Keys +Missing keys in it_IT.axaml - Text.Preferences.General.ShowTagsInGraph
-### pt_BR.axaml: 91.12% - +### ![pt__BR](https://img.shields.io/badge/pt__BR-91.12%25-yellow)
-Missing Keys +Missing keys in pt_BR.axaml - Text.AIAssistant.Regen - Text.AIAssistant.Use @@ -120,32 +116,8 @@
-### ru_RU.axaml: 100.00% +### ![ru__RU](https://img.shields.io/badge/ru__RU-%E2%88%9A-brightgreen) +### ![zh__CN](https://img.shields.io/badge/zh__CN-%E2%88%9A-brightgreen) -
-Missing Keys - - - -
- -### zh_CN.axaml: 100.00% - - -
-Missing Keys - - - -
- -### zh_TW.axaml: 100.00% - - -
-Missing Keys - - - -
+### ![zh__TW](https://img.shields.io/badge/zh__TW-%E2%88%9A-brightgreen) \ No newline at end of file diff --git a/build/scripts/localization-check.js b/build/scripts/localization-check.js index ed89a5e8..1e8f1f0d 100644 --- a/build/scripts/localization-check.js +++ b/build/scripts/localization-check.js @@ -6,7 +6,6 @@ const repoRoot = path.join(__dirname, '../../'); const localesDir = path.join(repoRoot, 'src/Resources/Locales'); const enUSFile = path.join(localesDir, 'en_US.axaml'); const outputFile = path.join(repoRoot, 'TRANSLATION.md'); -const readmeFile = path.join(repoRoot, 'README.md'); const parser = new xml2js.Parser(); @@ -18,46 +17,36 @@ async function parseXml(filePath) { async function calculateTranslationRate() { const enUSData = await parseXml(enUSFile); const enUSKeys = new Set(enUSData.ResourceDictionary['x:String'].map(item => item.$['x:Key'])); - - const translationRates = []; - const badges = []; - const files = (await fs.readdir(localesDir)).filter(file => file !== 'en_US.axaml' && file.endsWith('.axaml')); - // Add en_US badge first - badges.push(`[![en_US](https://img.shields.io/badge/en__US-%E2%88%9A-brightgreen)](TRANSLATION.md)`); + const lines = []; + + lines.push('# Translation Status'); + lines.push('This document shows the translation status of each locale file in the repository.'); + lines.push(`## Details`); + lines.push(`### ![en_US](https://img.shields.io/badge/en__US-%E2%88%9A-brightgreen)`); for (const file of files) { + const locale = file.replace('.axaml', '').replace('_', '__'); const filePath = path.join(localesDir, file); const localeData = await parseXml(filePath); const localeKeys = new Set(localeData.ResourceDictionary['x:String'].map(item => item.$['x:Key'])); - const missingKeys = [...enUSKeys].filter(key => !localeKeys.has(key)); - const translationRate = ((enUSKeys.size - missingKeys.length) / enUSKeys.size) * 100; - translationRates.push(`### ${file}: ${translationRate.toFixed(2)}%\n`); - translationRates.push(`
\nMissing Keys\n\n${missingKeys.map(key => `- ${key}`).join('\n')}\n\n
`); + if (missingKeys.length > 0) { + const progress = ((enUSKeys.size - missingKeys.length) / enUSKeys.size) * 100; + const badgeColor = progress >= 75 ? 'yellow' : 'red'; - // Add badges - const locale = file.replace('.axaml', '').replace('_', '__'); - if (translationRate === 100) { - badges.push(`[![${locale}](https://img.shields.io/badge/${locale}-%E2%88%9A-brightgreen)](TRANSLATION.md)`); + lines.push(`### ![${locale}](https://img.shields.io/badge/${locale}-${progress.toFixed(2)}%25-${badgeColor})`); + lines.push(`
\nMissing keys in ${file}\n\n${missingKeys.map(key => `- ${key}`).join('\n')}\n\n
`) } else { - const badgeColor = translationRate >= 75 ? 'yellow' : 'red'; - badges.push(`[![${locale}](https://img.shields.io/badge/${locale}-${translationRate.toFixed(2)}%25-${badgeColor})](TRANSLATION.md)`); - } + lines.push(`### ![${locale}](https://img.shields.io/badge/${locale}-%E2%88%9A-brightgreen)`); + } } - console.log(translationRates.join('\n\n')); - - await fs.writeFile(outputFile, translationRates.join('\n\n') + '\n', 'utf8'); - - // Update README.md - let readmeContent = await fs.readFile(readmeFile, 'utf8'); - const badgeSection = `## Translation Status\n\n${badges.join(' ')}`; - console.log(badgeSection); - readmeContent = readmeContent.replace(/## Translation Status\n\n.*\n\n/, badgeSection + '\n\n'); - await fs.writeFile(readmeFile, readmeContent, 'utf8'); + const content = lines.join('\n\n'); + console.log(content); + await fs.writeFile(outputFile, content, 'utf8'); } calculateTranslationRate().catch(err => console.error(err));