forked from MapComplete/MapComplete
Reformat all files with prettier
This commit is contained in:
parent
e22d189376
commit
b541d3eab4
382 changed files with 50893 additions and 35566 deletions
|
@ -1,5 +1,5 @@
|
|||
import * as languages from "../assets/generated/used_languages.json"
|
||||
import {readFileSync, writeFileSync} from "fs";
|
||||
import { readFileSync, writeFileSync } from "fs"
|
||||
|
||||
/**
|
||||
* Moves values around in 'section'. Section will be changed
|
||||
|
@ -8,54 +8,57 @@ import {readFileSync, writeFileSync} from "fs";
|
|||
* @param language
|
||||
*/
|
||||
function fixSection(section, referenceSection, language: string) {
|
||||
if(section === undefined){
|
||||
if (section === undefined) {
|
||||
return
|
||||
}
|
||||
outer: for (const key of Object.keys(section)) {
|
||||
const v = section[key]
|
||||
if(typeof v ==="string" && referenceSection[key] === undefined){
|
||||
if (typeof v === "string" && referenceSection[key] === undefined) {
|
||||
// Not found in reference, search for a subsection with this key
|
||||
for (const subkey of Object.keys(referenceSection)) {
|
||||
const subreference = referenceSection[subkey]
|
||||
if(subreference[key] !== undefined){
|
||||
if(section[subkey] !== undefined && section[subkey][key] !== undefined) {
|
||||
if (subreference[key] !== undefined) {
|
||||
if (section[subkey] !== undefined && section[subkey][key] !== undefined) {
|
||||
console.log(`${subkey}${key} is already defined... Looking furhter`)
|
||||
continue
|
||||
}
|
||||
if(typeof section[subkey] === "string"){
|
||||
console.log(`NOT overwriting '${section[subkey]}' for ${subkey} (needed for ${key})`)
|
||||
}else{
|
||||
if (typeof section[subkey] === "string") {
|
||||
console.log(
|
||||
`NOT overwriting '${section[subkey]}' for ${subkey} (needed for ${key})`
|
||||
)
|
||||
} else {
|
||||
// apply fix
|
||||
if(section[subkey] === undefined){
|
||||
if (section[subkey] === undefined) {
|
||||
section[subkey] = {}
|
||||
}
|
||||
section[subkey][key] = section[key]
|
||||
delete section[key]
|
||||
console.log(`Rewritten key: ${key} --> ${subkey}.${key} in language ${language}`)
|
||||
delete section[key]
|
||||
console.log(
|
||||
`Rewritten key: ${key} --> ${subkey}.${key} in language ${language}`
|
||||
)
|
||||
continue outer
|
||||
}
|
||||
}
|
||||
}
|
||||
console.log("No solution found for "+key)
|
||||
console.log("No solution found for " + key)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function main(args:string[]):void{
|
||||
function main(args: string[]): void {
|
||||
const sectionName = args[0]
|
||||
const l = args[1]
|
||||
if(sectionName === undefined){
|
||||
console.log("Tries to automatically move translations to a new subsegment. Usage: 'sectionToCheck' 'language'")
|
||||
if (sectionName === undefined) {
|
||||
console.log(
|
||||
"Tries to automatically move translations to a new subsegment. Usage: 'sectionToCheck' 'language'"
|
||||
)
|
||||
return
|
||||
}
|
||||
const reference = JSON.parse( readFileSync("./langs/en.json","UTF8"))
|
||||
const reference = JSON.parse(readFileSync("./langs/en.json", "UTF8"))
|
||||
const path = `./langs/${l}.json`
|
||||
const file = JSON.parse( readFileSync(path,"UTF8"))
|
||||
const file = JSON.parse(readFileSync(path, "UTF8"))
|
||||
fixSection(file[sectionName], reference[sectionName], l)
|
||||
writeFileSync(path, JSON.stringify(file, null, " ")+"\n")
|
||||
|
||||
|
||||
writeFileSync(path, JSON.stringify(file, null, " ") + "\n")
|
||||
}
|
||||
|
||||
main(process.argv.slice(2))
|
||||
main(process.argv.slice(2))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue