forked from MapComplete/MapComplete
Housekeeping...
This commit is contained in:
parent
7017caf502
commit
d5d2c08706
120 changed files with 8537 additions and 2515 deletions
|
@ -27,10 +27,10 @@ async function fetchRegularLanguages() {
|
|||
"{ \n" +
|
||||
" ?lang wdt:P31 wd:Q1288568. \n" + // language instanceOf (p31) modern language(Q1288568)
|
||||
" ?lang rdfs:label ?label. \n" +
|
||||
" ?lang wdt:P282 ?writing_system. \n"+
|
||||
" ?lang wdt:P282 ?writing_system. \n" +
|
||||
" ?writing_system wdt:P1406 ?directionality. \n" +
|
||||
" ?lang wdt:P424 ?code. \n" +// Wikimedia language code seems to be close to the weblate entries
|
||||
" SERVICE wikibase:label { bd:serviceParam wikibase:language \"en\". } \n" +
|
||||
" ?lang wdt:P424 ?code. \n" + // Wikimedia language code seems to be close to the weblate entries
|
||||
' SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } \n' +
|
||||
"} "
|
||||
const url = wds.sparqlQuery(sparql)
|
||||
|
||||
|
@ -81,8 +81,8 @@ function getNativeList(langs: Map<string, { translations: Map<string, string> }>
|
|||
continue
|
||||
}
|
||||
native[key] = translations.get(key)
|
||||
if(native[key] === undefined){
|
||||
console.log("No native translation found for "+key)
|
||||
if (native[key] === undefined) {
|
||||
console.log("No native translation found for " + key)
|
||||
}
|
||||
}
|
||||
return native
|
||||
|
@ -115,7 +115,9 @@ async function getOfficialLanguagesPerCountry(): Promise<Map<string, string[]>>
|
|||
return lngs
|
||||
}
|
||||
|
||||
async function getOfficialLanguagesPerCountryCached(wipeCache: boolean): Promise<Record<string /*Country code*/, string[] /*Language codes*/>>{
|
||||
async function getOfficialLanguagesPerCountryCached(
|
||||
wipeCache: boolean
|
||||
): Promise<Record<string /*Country code*/, string[] /*Language codes*/>> {
|
||||
let officialLanguages: Record<string, string[]>
|
||||
const officialLanguagesPath = "./assets/language_in_country.json"
|
||||
if (existsSync("./assets/languages_in_country.json") && !wipeCache) {
|
||||
|
@ -136,36 +138,33 @@ async function main(wipeCache = false) {
|
|||
console.log("Reusing the cached file")
|
||||
}
|
||||
|
||||
|
||||
const data = JSON.parse(readFileSync(cacheFile, "UTF8"))
|
||||
const perId = WikidataUtils.extractLanguageData(data, WikidataUtils.languageRemapping)
|
||||
const nativeList = getNativeList(perId)
|
||||
writeFileSync("./assets/language_native.json", JSON.stringify(nativeList, null, " "))
|
||||
const languagesPerCountry = Utils.TransposeMap(await getOfficialLanguagesPerCountryCached(wipeCache))
|
||||
const languagesPerCountry = Utils.TransposeMap(
|
||||
await getOfficialLanguagesPerCountryCached(wipeCache)
|
||||
)
|
||||
const translations = Utils.MapToObj(perId, (value, key) => {
|
||||
// We keep all language codes in the list...
|
||||
const translatedForId : Record<string, string | {countries?: string[], dir: string[]}> = Utils.MapToObj(value.translations, (v, k) => {
|
||||
if (!LanguageUtils.usedLanguages.has(k)) {
|
||||
// ... but don't keep translations if we don't have a displayed language for them
|
||||
return undefined
|
||||
}
|
||||
return v
|
||||
})
|
||||
const translatedForId: Record<string, string | { countries?: string[]; dir: string[] }> =
|
||||
Utils.MapToObj(value.translations, (v, k) => {
|
||||
if (!LanguageUtils.usedLanguages.has(k)) {
|
||||
// ... but don't keep translations if we don't have a displayed language for them
|
||||
return undefined
|
||||
}
|
||||
return v
|
||||
})
|
||||
|
||||
translatedForId["_meta"] = {
|
||||
countries : Utils.Dedup( languagesPerCountry[key]),
|
||||
dir: value.directionality
|
||||
countries: Utils.Dedup(languagesPerCountry[key]),
|
||||
dir: value.directionality,
|
||||
}
|
||||
|
||||
return translatedForId
|
||||
})
|
||||
|
||||
writeFileSync("./assets/language_translations.json", JSON.stringify(translations, null, " "))
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
const forceRefresh = process.argv[2] === "--force-refresh"
|
||||
|
|
|
@ -13,8 +13,8 @@ import QueryParameterDocumentation from "../UI/QueryParameterDocumentation"
|
|||
import ScriptUtils from "./ScriptUtils"
|
||||
import List from "../UI/Base/List"
|
||||
import SharedTagRenderings from "../Customizations/SharedTagRenderings"
|
||||
import {writeFile} from "fs";
|
||||
import Translations from "../UI/i18n/Translations";
|
||||
import { writeFile } from "fs"
|
||||
import Translations from "../UI/i18n/Translations"
|
||||
import * as themeOverview from "../assets/generated/theme_overview.json"
|
||||
|
||||
function WriteFile(
|
||||
|
@ -63,11 +63,14 @@ function WriteFile(
|
|||
/**
|
||||
* The wikitable is updated as some tools show an overview of apps based on the wiki.
|
||||
*/
|
||||
function generateWikipage(){
|
||||
|
||||
function generateWikiEntry(layout: { hideFromOverview: boolean, id: string, shortDescription: any }) {
|
||||
function generateWikipage() {
|
||||
function generateWikiEntry(layout: {
|
||||
hideFromOverview: boolean
|
||||
id: string
|
||||
shortDescription: any
|
||||
}) {
|
||||
if (layout.hideFromOverview) {
|
||||
return "";
|
||||
return ""
|
||||
}
|
||||
|
||||
const languagesInDescr = []
|
||||
|
@ -75,8 +78,8 @@ function generateWikipage(){
|
|||
languagesInDescr.push(shortDescriptionKey)
|
||||
}
|
||||
|
||||
const languages = languagesInDescr.map(ln => `{{#language:${ln}|en}}`).join(", ")
|
||||
let auth = "Yes";
|
||||
const languages = languagesInDescr.map((ln) => `{{#language:${ln}|en}}`).join(", ")
|
||||
let auth = "Yes"
|
||||
return `{{service_item
|
||||
|name= [https://mapcomplete.osm.be/${layout.id} ${layout.id}]
|
||||
|region= Worldwide
|
||||
|
@ -84,32 +87,32 @@ function generateWikipage(){
|
|||
|descr= A MapComplete theme: ${Translations.T(layout.shortDescription)
|
||||
.textFor("en")
|
||||
.replace("<a href='", "[[")
|
||||
.replace(/'>.*<\/a>/, "]]")
|
||||
}
|
||||
.replace(/'>.*<\/a>/, "]]")}
|
||||
|material= {{yes|[https://mapcomplete.osm.be/ ${auth}]}}
|
||||
|image= MapComplete_Screenshot.png
|
||||
|genre= POI, editor, ${layout.id}
|
||||
}}`
|
||||
}
|
||||
|
||||
let wikiPage = "{|class=\"wikitable sortable\"\n" +
|
||||
let wikiPage =
|
||||
'{|class="wikitable sortable"\n' +
|
||||
"! Name, link !! Genre !! Covered region !! Language !! Description !! Free materials !! Image\n" +
|
||||
"|-";
|
||||
"|-"
|
||||
|
||||
for (const layout of (themeOverview["default"] ?? themeOverview)) {
|
||||
for (const layout of themeOverview["default"] ?? themeOverview) {
|
||||
if (layout.hideFromOverview) {
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
wikiPage += "\n" + generateWikiEntry(layout);
|
||||
wikiPage += "\n" + generateWikiEntry(layout)
|
||||
}
|
||||
|
||||
wikiPage += "\n|}"
|
||||
|
||||
writeFile("Docs/wikiIndex.txt", wikiPage, (err) => {
|
||||
if (err !== null) {
|
||||
console.log("Could not save wikiindex", err);
|
||||
console.log("Could not save wikiindex", err)
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
console.log("Starting documentation generation...")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue