forked from MapComplete/MapComplete
Add some statistics on translations in script
This commit is contained in:
parent
796ee40f3b
commit
e22ce4d5b1
3 changed files with 135 additions and 73 deletions
|
@ -2,6 +2,8 @@ import * as fs from "fs";
|
|||
import {readFileSync, writeFileSync} from "fs";
|
||||
import {Utils} from "../Utils";
|
||||
import ScriptUtils from "./ScriptUtils";
|
||||
import {AllKnownLayouts} from "../Customizations/AllKnownLayouts";
|
||||
import TranslatorsPanel from "../UI/BigComponents/TranslatorsPanel";
|
||||
|
||||
const knownLanguages = ["en", "nl", "de", "fr", "es", "gl", "ca"];
|
||||
|
||||
|
@ -534,7 +536,7 @@ const l1 = generateTranslationsObjectFrom(ScriptUtils.getLayerFiles(), "layers")
|
|||
const l2 = generateTranslationsObjectFrom(ScriptUtils.getThemeFiles().filter(th => th.parsed.mustHaveLanguage === undefined), "themes")
|
||||
const l3 = generateTranslationsObjectFrom([{path: questionsPath, parsed: questionsParsed}], "shared-questions")
|
||||
|
||||
const usedLanguages = Utils.Dedup(l1.concat(l2).concat(l3)).filter(v => v !== "*")
|
||||
const usedLanguages: string[] = Utils.Dedup(l1.concat(l2).concat(l3)).filter(v => v !== "*")
|
||||
usedLanguages.sort()
|
||||
fs.writeFileSync("./assets/generated/used_languages.json", JSON.stringify({languages: usedLanguages}))
|
||||
|
||||
|
@ -555,3 +557,39 @@ TranslationPart.fromDirectory("./langs").validateStrict("./langs")
|
|||
TranslationPart.fromDirectory("./langs/layers").validateStrict("layers")
|
||||
TranslationPart.fromDirectory("./langs/themes").validateStrict("themes")
|
||||
TranslationPart.fromDirectory("./langs/shared-questions").validateStrict("shared-questions")
|
||||
|
||||
|
||||
// Some statistics
|
||||
console.log(Utils.FixedLength("",12)+" "+usedLanguages.map(l => Utils.FixedLength(l, 6)).join(""))
|
||||
const all = new Map<string, number[]>()
|
||||
|
||||
usedLanguages.forEach(ln => all.set(ln, []))
|
||||
|
||||
for (const layoutId of Array.from(AllKnownLayouts.allKnownLayouts.keys())) {
|
||||
const layout = AllKnownLayouts.allKnownLayouts.get(layoutId)
|
||||
|
||||
const {completeness, total} = TranslatorsPanel.MissingTranslationsFor(layout)
|
||||
process.stdout.write(Utils.FixedLength(layout.id, 12)+" ")
|
||||
for (const language of usedLanguages) {
|
||||
const compl = completeness.get(language)
|
||||
all.get(language).push((compl ?? 0) / total)
|
||||
if(compl === undefined){
|
||||
process.stdout.write(" ")
|
||||
continue
|
||||
}
|
||||
const percentage = Math.round(100 * compl / total)
|
||||
process.stdout.write(Utils.FixedLength(percentage+"%", 6))
|
||||
}
|
||||
process.stdout.write("\n")
|
||||
}
|
||||
|
||||
process.stdout.write(Utils.FixedLength("average", 12)+" ")
|
||||
for (const language of usedLanguages) {
|
||||
const ratios = all.get(language)
|
||||
let sum = 0
|
||||
ratios.forEach(x => sum += x)
|
||||
const percentage = Math.round(100 * (sum / ratios.length))
|
||||
process.stdout.write(Utils.FixedLength(percentage+"% ", 6))
|
||||
}
|
||||
process.stdout.write("\n")
|
||||
console.log(Utils.FixedLength("",12)+" "+usedLanguages.map(l => Utils.FixedLength(l, 6)).join(""))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue