forked from MapComplete/MapComplete
Wikidata language picker
This commit is contained in:
parent
b75581405e
commit
325e30666b
14 changed files with 335 additions and 213 deletions
86
scripts/thieves/stealLanguages.ts
Normal file
86
scripts/thieves/stealLanguages.ts
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
/*
|
||||
* Uses the languages in and to every translation from wikidata to generate a language question in wikidata/wikidata
|
||||
* */
|
||||
|
||||
import WikidataUtils from "../../Utils/WikidataUtils";
|
||||
import {existsSync, mkdirSync, readFileSync, writeFileSync} from "fs";
|
||||
import {LayerConfigJson} from "../../Models/ThemeConfig/Json/LayerConfigJson";
|
||||
import {MappingConfigJson} from "../../Models/ThemeConfig/Json/QuestionableTagRenderingConfigJson";
|
||||
import LanguageUtils from "../../Utils/LanguageUtils";
|
||||
|
||||
function main(){
|
||||
const sourcepath = "assets/generated/languages-wd.json";
|
||||
console.log(`Converting language data file '${sourcepath}' into a tagMapping`)
|
||||
const languages = WikidataUtils.extractLanguageData(JSON.parse(readFileSync(sourcepath, "utf8")), {})
|
||||
const mappings : MappingConfigJson[] = []
|
||||
const schoolmappings : MappingConfigJson[] = []
|
||||
|
||||
languages.forEach((l, code) => {
|
||||
const then : Record<string, string>= {}
|
||||
l.forEach((tr, lng) => {
|
||||
const languageCodeWeblate = WikidataUtils.languageRemapping[lng] ?? lng;
|
||||
if(!LanguageUtils.usedLanguages.has(languageCodeWeblate)){
|
||||
return;
|
||||
}
|
||||
then[languageCodeWeblate] = tr
|
||||
})
|
||||
mappings.push(<MappingConfigJson>{
|
||||
if: "language:" + code + "=yes",
|
||||
ifnot: "language:" + code + "=",
|
||||
searchTerms: {
|
||||
"*": [code]
|
||||
},
|
||||
then
|
||||
})
|
||||
|
||||
schoolmappings.push(<MappingConfigJson>{
|
||||
if: "school:language=" + code,
|
||||
then
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
const wikidataLayer = <LayerConfigJson>{
|
||||
id: "wikidata",
|
||||
description: "Various tagrenderings which are generated from Wikidata. Automatically generated with a script, don't edit manually",
|
||||
"#dont-translate": "*",
|
||||
"source": {
|
||||
"osmTags": "id~*"
|
||||
},
|
||||
"mapRendering": null,
|
||||
tagRenderings: [
|
||||
{
|
||||
id: "language",
|
||||
// @ts-ignore
|
||||
description: "Enables to pick *a single* 'language:<lng>=yes' within the mappings",
|
||||
mappings,
|
||||
},
|
||||
{
|
||||
builtin: "wikidata.language",
|
||||
override: {
|
||||
id: "language-multi",
|
||||
// @ts-ignore
|
||||
description: "Enables to pick *multiple* 'language:<lng>=yes' within the mappings",
|
||||
multiAnswer: true
|
||||
}
|
||||
|
||||
},
|
||||
{
|
||||
id:"school-language",
|
||||
// @ts-ignore
|
||||
description: "Enables to pick a single 'school:language=<lng>' within the mappings",
|
||||
multiAnswer: true,
|
||||
mappings: schoolmappings
|
||||
}
|
||||
]
|
||||
}
|
||||
const dir = "./assets/layers/wikidata/"
|
||||
if(!existsSync(dir)){
|
||||
mkdirSync(dir)
|
||||
}
|
||||
const path = dir + "wikidata.json"
|
||||
writeFileSync(path, JSON.stringify(wikidataLayer, null, " "))
|
||||
console.log("Written "+path)
|
||||
}
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue