Move translation checks to the validation step

This commit is contained in:
pietervdvn 2021-04-23 16:52:20 +02:00
parent 127ad9c947
commit 5c0e3662c1
2 changed files with 23 additions and 4 deletions

View file

@ -67,6 +67,11 @@ function validateLayer(layerJson: LayerConfigJson, path: string, knownPaths: Set
} }
for (const image of images) { for (const image of images) {
if(image.indexOf("{") >= 0){
console.warn("Ignoring image with { in the path: ", image)
continue
}
if (!knownPaths.has(image)) { if (!knownPaths.has(image)) {
const ctx = context === undefined ? "" : ` in a layer defined in the theme ${context}` const ctx = context === undefined ? "" : ` in a layer defined in the theme ${context}`
errorCount.push(`Image with path ${image} not found or not attributed; it is used in ${layer.id}${ctx}`) errorCount.push(`Image with path ${image} not found or not attributed; it is used in ${layer.id}${ctx}`)
@ -133,9 +138,6 @@ function validateTranslationCompletenessOfObject(object: any, expectedLanguages:
isComplete = false; isComplete = false;
} }
} }
if (!isComplete) {
console.log(message)
}
return missingTranlations return missingTranlations
} }
@ -205,11 +207,15 @@ function main(args: string[]) {
} }
if(missingTranslations.length > 0){ if(missingTranslations.length > 0){
console.log(missingTranslations.length, "missing translations")
writeFileSync("missing_translations.txt", missingTranslations.join("\n")) writeFileSync("missing_translations.txt", missingTranslations.join("\n"))
} }
if (layerErrorCount.length + themeErrorCount.length == 0) { if (layerErrorCount.length + themeErrorCount.length == 0) {
console.log("All good!") console.log("All good!")
// We load again from disc, as modifications were made above
const lt = loadThemesAndLayers();
writeFiles(lt); writeFiles(lt);
} else { } else {
const errors = layerErrorCount.concat(themeErrorCount).join("\n") const errors = layerErrorCount.concat(themeErrorCount).join("\n")

View file

@ -189,12 +189,25 @@ const contents = ScriptUtils.readDirRecSync("./assets")
.filter(entry => entry.indexOf("./assets/generated") != 0) .filter(entry => entry.indexOf("./assets/generated") != 0)
const licensePaths = contents.filter(entry => entry.indexOf("license_info.json") >= 0) const licensePaths = contents.filter(entry => entry.indexOf("license_info.json") >= 0)
const licenseInfos = generateLicenseInfos(licensePaths); const licenseInfos = generateLicenseInfos(licensePaths);
writeFileSync("./assets/generated/license_info.json", JSON.stringify(licenseInfos, null, " ")) writeFileSync("./assets/generated/license_info.json", JSON.stringify(licenseInfos, null, " "))
const artwork = contents.filter(pth => pth.match(/(.svg|.png|.jpg)$/i) != null) const artwork = contents.filter(pth => pth.match(/(.svg|.png|.jpg)$/i) != null)
const missingLicenses = missingLicenseInfos(licenseInfos, artwork) const missingLicenses = missingLicenseInfos(licenseInfos, artwork)
const invalidLicenses = licenseInfos.filter(l => (l.license ?? "") === "").map(l => `License for artwork ${l.path} is empty string or undefined`) const invalidLicenses = licenseInfos.filter(l => (l.license ?? "") === "").map(l => `License for artwork ${l.path} is empty string or undefined`)
for (const licenseInfo of licenseInfos) {
for (const source of licenseInfo.sources) {
if(source == ""){
invalidLicenses.push("Invalid license: empty string in "+JSON.stringify(licenseInfo))
}
try{
new URL(source);
}catch{
invalidLicenses.push("Not a valid URL: "+source)
}
}
}
if (process.argv.indexOf("--prompt") >= 0 || process.argv.indexOf("--query") >= 0) { if (process.argv.indexOf("--prompt") >= 0 || process.argv.indexOf("--query") >= 0) {
queryMissingLicenses(missingLicenses) queryMissingLicenses(missingLicenses)
} }