forked from MapComplete/MapComplete
IMprovements to removeTranslation script
This commit is contained in:
parent
d9a64dc3a8
commit
af4cde9ec1
1 changed files with 15 additions and 3 deletions
|
@ -27,10 +27,22 @@ async function main(args: string[]) {
|
||||||
const path = args[0].split(".")
|
const path = args[0].split(".")
|
||||||
console.log("Removing translation string ", path, "from the translations for " + directory)
|
console.log("Removing translation string ", path, "from the translations for " + directory)
|
||||||
const files = ScriptUtils.readDirRecSync(directory, 1).filter((f) => f.endsWith(".json"))
|
const files = ScriptUtils.readDirRecSync(directory, 1).filter((f) => f.endsWith(".json"))
|
||||||
|
const removedLanguages: string[] = []
|
||||||
for (const file of files) {
|
for (const file of files) {
|
||||||
const json = JSON.parse(fs.readFileSync(file, { encoding: "utf-8" }))
|
const rawContents = fs.readFileSync(file, { encoding: "utf-8" })
|
||||||
Utils.WalkPath(path, json, (_) => undefined)
|
const json = JSON.parse(rawContents)
|
||||||
fs.writeFileSync(file, JSON.stringify(json, null, " ") + "\n")
|
Utils.WalkPath(path, json, (found) => {
|
||||||
|
removedLanguages.push(file)
|
||||||
|
console.log("Removing ",found)
|
||||||
|
return undefined
|
||||||
|
})
|
||||||
|
const lastChar = rawContents.endsWith("\n") ? "\n" : ""
|
||||||
|
fs.writeFileSync(file, JSON.stringify(json, null, " ") + lastChar)
|
||||||
|
}
|
||||||
|
if(removedLanguages.length === 0){
|
||||||
|
console.warn("No items removed. Doublecheck the paths")
|
||||||
|
}else{
|
||||||
|
console.log("Removed items in "+removedLanguages.join(", "))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue