From d5443b4413ed62c181313a034f01a4cacfeb1ac5 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Fri, 23 Sep 2022 01:28:53 +0200 Subject: [PATCH] Add translation statistics --- UI/BigComponents/PdfExportGui.ts | 22 +++++++++++++++------- Utils/svgToPdf.ts | 12 ++++++++---- 2 files changed, 23 insertions(+), 11 deletions(-) diff --git a/UI/BigComponents/PdfExportGui.ts b/UI/BigComponents/PdfExportGui.ts index b249dad86..f73ed9484 100644 --- a/UI/BigComponents/PdfExportGui.ts +++ b/UI/BigComponents/PdfExportGui.ts @@ -14,7 +14,7 @@ import Loading from "../Base/Loading"; import BaseUIElement from "../BaseUIElement"; import Img from "../Base/Img"; import Title from "../Base/Title"; -import CheckBoxes, {CheckBox} from "../Input/Checkboxes"; +import {CheckBox} from "../Input/Checkboxes"; import Minimap from "../Base/Minimap"; import SearchAndGo from "./SearchAndGo"; import Toggle from "../Input/Toggle"; @@ -183,7 +183,7 @@ class PreparePdf extends Combine implements FlowStep<{ svgToPdf: SvgToPdf, langu new FixedInputElement("English", "en") ] const langs: string[] = Array.from(Object.keys(languages["default"] ?? languages)) - console.log("Available languages are:",langs) + console.log("Available languages are:", langs) const languageSelector = new SearchablePillsSelector( langs.map(l => ({ show: new Translation(languages[l]), @@ -246,25 +246,33 @@ class InspectStrings extends Toggle implements FlowStep<{ svgToPdf: SvgToPdf, la private static createOverviewPanel(svgToPdf: SvgToPdf, language: string): BaseUIElement { const elements: BaseUIElement[] = [] - - for (const translationKey of Array.from(svgToPdf.translationKeys())) { + let foundTranslations = 0 + const allKeys = Array.from(svgToPdf.translationKeys()) + for (const translationKey of allKeys) { let spec = translationKey if (translationKey.startsWith("layer.")) { spec = "layers:" + translationKey.substring(6) } else { spec = "core:" + translationKey } + const translated = svgToPdf.getTranslation("$" + translationKey, language, true) + if (translated) { + foundTranslations++ + } + const linkToWeblate = new Link(spec, LinkToWeblate.hrefToWeblate(language, spec), true).SetClass("font-bold link-underline") elements.push(new Combine([ - new Link(spec, LinkToWeblate.hrefToWeblate(language, spec), true).SetClass("font-bold link-underline"), + linkToWeblate, " ", - svgToPdf.getTranslation("$" + translationKey, language, true) ?? new FixedUiElement("No translation found!").SetClass("alert") + translated ?? new FixedUiElement("No translation found!").SetClass("alert") ])) } return new Toggleable( new Title("Translations for " + language), - new Combine(["The following keys are used:", + new Combine([ + `${foundTranslations}/${allKeys.length} of translations are found (${Math.floor(100 * foundTranslations / allKeys.length)}%)`, + "The following keys are used:", new List(elements) ]), {closeOnClick: false, height: "15rem"}) diff --git a/Utils/svgToPdf.ts b/Utils/svgToPdf.ts index c03b49982..cff6a37fd 100644 --- a/Utils/svgToPdf.ts +++ b/Utils/svgToPdf.ts @@ -820,12 +820,12 @@ export class SvgToPdfPage { t = new TypedTranslation({"*": t}) } if (t instanceof TypedTranslation) { - if (strict && t.translations[language] === undefined) { + if (strict && (t.translations[language] ?? t.translations["*"]) === undefined) { return undefined } return t.Subs(this.options.textSubstitutions).textFor(language) + rest } else if (t instanceof Translation) { - if (strict && t.translations[language] === undefined) { + if (strict && (t.translations[language] ?? t.translations["*"]) === undefined) { return undefined } return (t).textFor(language) + rest @@ -935,9 +935,13 @@ export class SvgToPdf { getTranslation(translationKey: string, language: string, strict: boolean = false) { for (const page of this._pages) { const tr = page.extractTranslation(translationKey, language, strict) - if (tr !== undefined && tr !== translationKey) { - return tr + if(tr === undefined){ + continue } + if(tr === translationKey){ + continue + } + return tr } return undefined }