Procházet zdrojové kódy

ref: better tr progress md generation

Sven před 1 rokem
rodič
revize
92ab70fa71

+ 36 - 12
assets/translations/README.md

@@ -1,25 +1,49 @@
+<!--
+    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+    !!             THIS IS A GENERATED FILE             !!
+    !!    all changes will be overwritten next build    !!
+    !! only edit in `src/tools/tr-progress-template.md` !!
+    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+-->
+
+
+
+
+
+
+
 ## BetterYTM - Translations
 To submit or edit a translation, please follow [this guide](../../contributing.md#submitting-translations)
 
 <br>
 
 ### Translation progress:
-| Locale | Translated keys | Based on |
-| ------ | --------------- | :------: |
-| [`en_US`](./en_US.json) | 164 (default locale) |  |
-| [`de_DE`](./de_DE.json) | ✅ `164/164` (100.0%) | ─ |
-| [`en_UK`](./en_UK.json) | ✅ `164/164` (100.0%) | `en_US` |
-| [`es_ES`](./es_ES.json) | ✅ `164/164` (100.0%) | ─ |
-| [`fr_FR`](./fr_FR.json) | ✅ `164/164` (100.0%) | ─ |
-| [`hi_IN`](./hi_IN.json) | ✅ `164/164` (100.0%) | ─ |
-| [`ja_JA`](./ja_JA.json) | ✅ `164/164` (100.0%) | ─ |
-| [`pt_BR`](./pt_BR.json) | ✅ `164/164` (100.0%) | ─ |
-| [`zh_CN`](./zh_CN.json) | ✅ `164/164` (100.0%) | ─ |
+| &nbsp; | Locale | Translated keys | Based on |
+| :----: | ------ | --------------- | :------: |
+| ─ | [`en_US`](./en_US.json) | 164 (default locale) |  |
+| ✅ | [`de_DE`](./de_DE.json) | `164/164` (100%) | ─ |
+| ─ | [`en_UK`](./en_UK.json) | `164/164` (100%) | `en_US` |
+| ✅ | [`es_ES`](./es_ES.json) | `164/164` (100%) | ─ |
+| ✅ | [`fr_FR`](./fr_FR.json) | `164/164` (100%) | ─ |
+| ✅ | [`hi_IN`](./hi_IN.json) | `164/164` (100%) | ─ |
+| ✅ | [`ja_JA`](./ja_JA.json) | `164/164` (100%) | ─ |
+| ✅ | [`pt_BR`](./pt_BR.json) | `164/164` (100%) | ─ |
+| ✅ | [`zh_CN`](./zh_CN.json) | `164/164` (100%) | ─ |
+
+<sub>
+✅ - Fully translated
+</sub><br>
+<sub>
+⚠ - Almost fully translated
+</sub><br>
+<sub>
+‼️ - Partially translated
+</sub><br>
 
 <br>
 
 If a translation is based on another translation, that means the keys from the base translation file are automatically applied if they are missing. This is used for locales that are very similar to each other, such as `en_UK` and `en_US`  
-This means you need to manually check against the base translations for missing keys if you want to improve translations.
+This means to figure out which keys are untranslated, you will need to manually check against the base translation file.
 
 <br>
 

+ 11 - 3
src/tools/tr-progress-template.md

@@ -4,14 +4,22 @@ To submit or edit a translation, please follow [this guide](../../contributing.m
 <br>
 
 ### Translation progress:
-| Locale | Translated keys | Based on |
-| ------ | --------------- | :------: |
 <!--#{{TR_PROGRESS_TABLE}}-->
 
+<sub>
+✅ - Fully translated
+</sub><br>
+<sub>
+⚠ - Almost fully translated
+</sub><br>
+<sub>
+‼️ - Partially translated
+</sub><br>
+
 <br>
 
 If a translation is based on another translation, that means the keys from the base translation file are automatically applied if they are missing. This is used for locales that are very similar to each other, such as `en_UK` and `en_US`  
-This means you need to manually check against the base translations for missing keys if you want to improve translations.
+This means to figure out which keys are untranslated, you will need to manually check against the base translation file.
 
 <br>
 

+ 30 - 10
src/tools/tr-progress.ts

@@ -41,9 +41,9 @@ async function run() {
   const { en_US, ...restLocs } = translations;
   const progress = {} as Record<TrLocale, number>;
 
-  //#SECTION table
+  //#SECTION progress table
 
-  const tableLines: string[] = [];
+  const progTableLines: string[] = [];
 
   for(const [locale, translations] of Object.entries({ en_US, ...restLocs })) {
     for(const [k] of Object.entries(en_US)) {
@@ -56,15 +56,21 @@ async function run() {
 
     const trKeys = progress[locale as TrLocale];
     const origKeys = Object.keys(en_US).length;
-    const percent = mapRange(trKeys, 0, origKeys, 0, 100).toFixed(1);
+    const percent = Number(mapRange(trKeys, 0, origKeys, 0, 100).toFixed(1));
 
-    const sym = trKeys === origKeys ? "✅" : "🚫";
+    const sym = trKeys === origKeys
+      ? "✅"
+      : (
+        percent >= 95
+          ? "⚠"
+          : "‼️"
+      );
 
-    const keysCol = locale === "en_US" ? `${origKeys} (default locale)` : `${sym} \`${trKeys}/${origKeys}\` (${percent}%)`;
+    const keysCol = locale === "en_US" ? `${origKeys} (default locale)` : `\`${trKeys}/${origKeys}\` (${percent}%)`;
 
     const baseTr = trFiles[locale as TrLocale]?.base;
 
-    tableLines.push(`| [\`${locale}\`](./${locale}.json) | ${keysCol} | ${baseTr ? `\`${baseTr}\`` : (locale === "en_US" ? "" : "─")} |`);
+    progTableLines.push(`| ${locale === "en_US" || baseTr ? "─" : sym} | [\`${locale}\`](./${locale}.json) | ${keysCol} | ${baseTr ? `\`${baseTr}\`` : (locale === "en_US" ? "" : "─")} |`);
     console.log(`  ${sym} ${locale}: ${trKeys}/${origKeys} (${percent}%)${baseTr ? ` (base: ${baseTr})`: ""}`);
   }
 
@@ -90,11 +96,25 @@ ${lines.join("\n")}\n
 
   //#SECTION finalize
 
-  let templateCont = String(await readFile(join(rootDir, "src/tools/tr-progress-template.md"), "utf-8"));
-  templateCont = templateCont
-    .replace(/<!--#{{TR_PROGRESS_TABLE}}-->/m, tableLines.join("\n"))
+  const banner = `\
+<!--
+    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+    !!             THIS IS A GENERATED FILE             !!
+    !!    all changes will be overwritten next build    !!
+    !! only edit in \`src/tools/tr-progress-template.md\` !!
+    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+-->`;
+
+  const progTableHeader = `\
+| &nbsp; | Locale | Translated keys | Based on |
+| :----: | ------ | --------------- | :------: |`;
+
+  let readmeCont = String(await readFile(join(rootDir, "src/tools/tr-progress-template.md"), "utf-8"));
+
+  readmeCont = `${banner}${"\n".repeat(8)}${readmeCont}`
+    .replace(/<!--#{{TR_PROGRESS_TABLE}}-->/m, `${progTableHeader}\n${progTableLines.join("\n")}`)
     .replace(/<!--#{{TR_MISSING_KEYS}}-->/m, missingKeys.length > 0 ? missingKeys.join("\n") : "No missing keys");
-  await writeFile(join(trDir, "README.md"), templateCont);
+  await writeFile(join(trDir, "README.md"), readmeCont);
 
   console.log(`\n\x1b[32mFinished updating translation progress\x1b[0m - updated file at '${relative(rootDir, join(trDir, "README.md"))}'\n`);