Chore: reformat all files with prettier

This commit is contained in:
Pieter Vander Vennet 2023-06-14 20:39:36 +02:00
parent 5757ae5dea
commit d008dcb54d
214 changed files with 8926 additions and 8196 deletions

View file

@ -1,6 +1,6 @@
import * as fs from "fs"
import {existsSync, mkdirSync, readFileSync, writeFileSync} from "fs"
import {Utils} from "../Utils"
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs"
import { Utils } from "../Utils"
import ScriptUtils from "./ScriptUtils"
const knownLanguages = ["en", "nl", "de", "fr", "es", "gl", "ca"]
@ -12,7 +12,7 @@ class TranslationPart {
const files = ScriptUtils.readDirRecSync(path, 1).filter((file) => file.endsWith(".json"))
const rootTranslation = new TranslationPart()
for (const file of files) {
const content = JSON.parse(readFileSync(file, {encoding: "utf8"}))
const content = JSON.parse(readFileSync(file, { encoding: "utf8" }))
rootTranslation.addTranslation(file.substr(0, file.length - ".json".length), content)
}
return rootTranslation
@ -52,10 +52,10 @@ class TranslationPart {
if (typeof v != "string") {
console.error(
`Non-string object at ${context} in translation while trying to add the translation ` +
JSON.stringify(v) +
` to '` +
translationsKey +
"'. The offending object which _should_ be a translation is: ",
JSON.stringify(v) +
` to '` +
translationsKey +
"'. The offending object which _should_ be a translation is: ",
v,
"\n\nThe current object is (only showing en):",
this.toJson(),
@ -94,9 +94,9 @@ class TranslationPart {
if (noTranslate !== undefined) {
console.log(
"Ignoring some translations for " +
context +
": " +
dontTranslateKeys.join(", ")
context +
": " +
dontTranslateKeys.join(", ")
)
}
}
@ -242,14 +242,14 @@ class TranslationPart {
}
subparts = subparts.map((p) => p.split(/\(.*\)/)[0])
for (const subpart of subparts) {
neededSubparts.add({part: subpart, usedByLanguage: lang})
neededSubparts.add({ part: subpart, usedByLanguage: lang })
}
}
})
// Actually check for the needed sub-parts, e.g. that {key} isn't translated into {sleutel}
this.contents.forEach((value, key) => {
neededSubparts.forEach(({part, usedByLanguage}) => {
neededSubparts.forEach(({ part, usedByLanguage }) => {
if (typeof value !== "string") {
return
}
@ -659,8 +659,12 @@ function mergeLayerTranslations() {
const layerFiles = ScriptUtils.getLayerFiles()
for (const layerFile of layerFiles) {
mergeLayerTranslation(layerFile.parsed, layerFile.path, loadTranslationFilesFrom("layers"))
const endsWithNewline = readFileSync(layerFile.path, {encoding: "utf8"})?.endsWith("\n") ?? true
writeFileSync(layerFile.path, JSON.stringify(layerFile.parsed, null, " ") + (endsWithNewline ? "\n" : "")) // layers use 2 spaces
const endsWithNewline =
readFileSync(layerFile.path, { encoding: "utf8" })?.endsWith("\n") ?? true
writeFileSync(
layerFile.path,
JSON.stringify(layerFile.parsed, null, " ") + (endsWithNewline ? "\n" : "")
) // layers use 2 spaces
}
}
@ -675,8 +679,12 @@ function mergeThemeTranslations() {
const allTranslations = new TranslationPart()
allTranslations.recursiveAdd(config, themeFile.path)
const endsWithNewline = readFileSync(themeFile.path, {encoding: "utf8"})?.endsWith("\n") ?? true
writeFileSync(themeFile.path, JSON.stringify(config, null, " ") + (endsWithNewline ? "\n" : "")) // Themefiles use 2 spaces
const endsWithNewline =
readFileSync(themeFile.path, { encoding: "utf8" })?.endsWith("\n") ?? true
writeFileSync(
themeFile.path,
JSON.stringify(config, null, " ") + (endsWithNewline ? "\n" : "")
) // Themefiles use 2 spaces
}
}
@ -695,8 +703,11 @@ if (!themeOverwritesWeblate) {
questionsPath,
loadTranslationFilesFrom("shared-questions")
)
const endsWithNewline = readFileSync(questionsPath, {encoding: "utf8"}).endsWith("\n")
writeFileSync(questionsPath, JSON.stringify(questionsParsed, null, " ") + (endsWithNewline ? "\n" : ""))
const endsWithNewline = readFileSync(questionsPath, { encoding: "utf8" }).endsWith("\n")
writeFileSync(
questionsPath,
JSON.stringify(questionsParsed, null, " ") + (endsWithNewline ? "\n" : "")
)
} else {
console.log("Ignore weblate")
}
@ -707,13 +718,13 @@ const l2 = generateTranslationsObjectFrom(
"themes"
)
const l3 = generateTranslationsObjectFrom(
[{path: questionsPath, parsed: questionsParsed}],
[{ path: questionsPath, parsed: questionsParsed }],
"shared-questions"
)
const usedLanguages: string[] = Utils.Dedup(l1.concat(l2).concat(l3)).filter((v) => v !== "*")
usedLanguages.sort()
fs.writeFileSync("./assets/used_languages.json", JSON.stringify({languages: usedLanguages}))
fs.writeFileSync("./assets/used_languages.json", JSON.stringify({ languages: usedLanguages }))
if (!themeOverwritesWeblate) {
// Generates the core translations