Add translation statistics
This commit is contained in:
parent
b1b6e9b8de
commit
d5443b4413
2 changed files with 23 additions and 11 deletions
|
@ -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"})
|
||||
|
|
|
@ -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 (<Translation>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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue