Add mapcomplete workflow

This commit is contained in:
pietervdvn 2021-05-19 15:22:17 +02:00
parent bf5b5d3130
commit 2b1c53dc23
4 changed files with 1184 additions and 1126 deletions

View file

@ -82,7 +82,7 @@ To develop or deploy a version of MapComplete, have a look [to the guide](Docs/D
## Translating MapComplete
Help to translate mapcomplete via [Hosted Weblate]().
The core strings of MapComplete are translated on [Hosted Weblate](https://hosted.weblate.org/projects/mapcomplete/core/).
A theme has translations into the preset.json (`assets/themes/themename/themename.json`). To add a translation:
@ -92,6 +92,8 @@ A theme has translations into the preset.json (`assets/themes/themename/themenam
3. If you notice missing translations in the core of MapComplete, fork this project, open [the file containing all translations](https://github.com/pietervdvn/MapComplete/blob/master/assets/translations.json), add add a language string there
4. Send a pull request to update the languages, I'll gladly add it! It doesn't have to be a complete translation from the start ;)
(Note that themes will be moved to weblate in the future too)
## Architecture
### High-level overview

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,53 @@
import ScriptUtils from "./ScriptUtils";
import {readFileSync, writeFileSync} from "fs";
class TranslationPart {
contents: Map<string, TranslationPart | string> = new Map<string, TranslationPart | string>()
add(language: string, obj: any){
for (const key in obj) {
const v = obj[key]
if(!this.contents.has(key)){
this.contents.set(key, new TranslationPart())
}
const subpart = this.contents.get(key) as TranslationPart
if(typeof v === "string"){
subpart.contents.set(language, v)
}else{
subpart.add(language, v)
}
}
}
toJson(): string{
const parts = []
for (let key of Array.from(this.contents.keys()) ){
const value = this.contents.get(key);
if(typeof value === "string"){
parts.push(`\"${key}\": \"${value}\"`)
}else{
parts.push(`\"${key}\": ${(value as TranslationPart).toJson()}`);
}
}
return JSON.stringify(JSON.parse(`{${parts.join(",")}}`), null, " ");
}
}
const translations = ScriptUtils.readDirRecSync("./langs")
.filter(path => path.indexOf(".json") > 0)
const allTranslations = new TranslationPart()
for (const translationFile of translations) {
const contents = JSON.parse(readFileSync(translationFile, "utf-8"));
let language = translationFile.substring(translationFile.lastIndexOf("/") + 1)
language = language.substring(0, language.length-5)
allTranslations.add(language, contents)
}
writeFileSync("./assets/translations.json", allTranslations.toJson())