forked from MapComplete/MapComplete
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 BaseUIElement from "../BaseUIElement";
|
||||||
import Img from "../Base/Img";
|
import Img from "../Base/Img";
|
||||||
import Title from "../Base/Title";
|
import Title from "../Base/Title";
|
||||||
import CheckBoxes, {CheckBox} from "../Input/Checkboxes";
|
import {CheckBox} from "../Input/Checkboxes";
|
||||||
import Minimap from "../Base/Minimap";
|
import Minimap from "../Base/Minimap";
|
||||||
import SearchAndGo from "./SearchAndGo";
|
import SearchAndGo from "./SearchAndGo";
|
||||||
import Toggle from "../Input/Toggle";
|
import Toggle from "../Input/Toggle";
|
||||||
|
@ -183,7 +183,7 @@ class PreparePdf extends Combine implements FlowStep<{ svgToPdf: SvgToPdf, langu
|
||||||
new FixedInputElement("English", "en")
|
new FixedInputElement("English", "en")
|
||||||
]
|
]
|
||||||
const langs: string[] = Array.from(Object.keys(languages["default"] ?? languages))
|
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(
|
const languageSelector = new SearchablePillsSelector(
|
||||||
langs.map(l => ({
|
langs.map(l => ({
|
||||||
show: new Translation(languages[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 {
|
private static createOverviewPanel(svgToPdf: SvgToPdf, language: string): BaseUIElement {
|
||||||
const elements: BaseUIElement[] = []
|
const elements: BaseUIElement[] = []
|
||||||
|
let foundTranslations = 0
|
||||||
for (const translationKey of Array.from(svgToPdf.translationKeys())) {
|
const allKeys = Array.from(svgToPdf.translationKeys())
|
||||||
|
for (const translationKey of allKeys) {
|
||||||
let spec = translationKey
|
let spec = translationKey
|
||||||
if (translationKey.startsWith("layer.")) {
|
if (translationKey.startsWith("layer.")) {
|
||||||
spec = "layers:" + translationKey.substring(6)
|
spec = "layers:" + translationKey.substring(6)
|
||||||
} else {
|
} else {
|
||||||
spec = "core:" + translationKey
|
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([
|
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(
|
return new Toggleable(
|
||||||
new Title("Translations for " + language),
|
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)
|
new List(elements)
|
||||||
]),
|
]),
|
||||||
{closeOnClick: false, height: "15rem"})
|
{closeOnClick: false, height: "15rem"})
|
||||||
|
|
|
@ -820,12 +820,12 @@ export class SvgToPdfPage {
|
||||||
t = new TypedTranslation({"*": t})
|
t = new TypedTranslation({"*": t})
|
||||||
}
|
}
|
||||||
if (t instanceof TypedTranslation) {
|
if (t instanceof TypedTranslation) {
|
||||||
if (strict && t.translations[language] === undefined) {
|
if (strict && (t.translations[language] ?? t.translations["*"]) === undefined) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
return t.Subs(this.options.textSubstitutions).textFor(language) + rest
|
return t.Subs(this.options.textSubstitutions).textFor(language) + rest
|
||||||
} else if (t instanceof Translation) {
|
} else if (t instanceof Translation) {
|
||||||
if (strict && t.translations[language] === undefined) {
|
if (strict && (t.translations[language] ?? t.translations["*"]) === undefined) {
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
return (<Translation>t).textFor(language) + rest
|
return (<Translation>t).textFor(language) + rest
|
||||||
|
@ -935,9 +935,13 @@ export class SvgToPdf {
|
||||||
getTranslation(translationKey: string, language: string, strict: boolean = false) {
|
getTranslation(translationKey: string, language: string, strict: boolean = false) {
|
||||||
for (const page of this._pages) {
|
for (const page of this._pages) {
|
||||||
const tr = page.extractTranslation(translationKey, language, strict)
|
const tr = page.extractTranslation(translationKey, language, strict)
|
||||||
if (tr !== undefined && tr !== translationKey) {
|
if(tr === undefined){
|
||||||
return tr
|
continue
|
||||||
}
|
}
|
||||||
|
if(tr === translationKey){
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
return tr
|
||||||
}
|
}
|
||||||
return undefined
|
return undefined
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue