forked from MapComplete/MapComplete
Fix fetchLanguage, regenerate language overview
This commit is contained in:
parent
657168e1f3
commit
06998172f0
3 changed files with 308 additions and 143 deletions
|
@ -149,7 +149,6 @@
|
||||||
],
|
],
|
||||||
"CY": [
|
"CY": [
|
||||||
"tr",
|
"tr",
|
||||||
"el",
|
|
||||||
"el"
|
"el"
|
||||||
],
|
],
|
||||||
"CZ": [
|
"CZ": [
|
||||||
|
@ -249,9 +248,6 @@
|
||||||
"es",
|
"es",
|
||||||
"pt"
|
"pt"
|
||||||
],
|
],
|
||||||
"GR": [
|
|
||||||
"el"
|
|
||||||
],
|
|
||||||
"GT": [
|
"GT": [
|
||||||
"es"
|
"es"
|
||||||
],
|
],
|
||||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -4,17 +4,17 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import * as wds from "wikidata-sdk"
|
import * as wds from "wikidata-sdk"
|
||||||
import {Utils} from "../Utils"
|
import { Utils } from "../Utils"
|
||||||
import ScriptUtils from "./ScriptUtils"
|
import ScriptUtils from "./ScriptUtils"
|
||||||
import {existsSync, readFileSync, writeFileSync} from "fs"
|
import { existsSync, readFileSync, writeFileSync } from "fs"
|
||||||
import WikidataUtils from "../Utils/WikidataUtils"
|
import WikidataUtils from "../Utils/WikidataUtils"
|
||||||
import LanguageUtils from "../Utils/LanguageUtils"
|
import LanguageUtils from "../Utils/LanguageUtils"
|
||||||
import Wikidata from "../Logic/Web/Wikidata";
|
import Wikidata from "../Logic/Web/Wikidata"
|
||||||
|
|
||||||
interface value<T> {
|
interface value<T> {
|
||||||
value: T,
|
value: T
|
||||||
type: "uri" | "literal" | string
|
type: "uri" | "literal" | string
|
||||||
'xml:lang'?: string
|
"xml:lang"?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LanguageSpecResult {
|
interface LanguageSpecResult {
|
||||||
|
@ -48,18 +48,18 @@ async function fetchRegularLanguages() {
|
||||||
|
|
||||||
// request the generated URL with your favorite HTTP request library
|
// request the generated URL with your favorite HTTP request library
|
||||||
const result = await Utils.downloadJson(url, { "User-Agent": "MapComplete script" })
|
const result = await Utils.downloadJson(url, { "User-Agent": "MapComplete script" })
|
||||||
const bindings = <LanguageSpecResult[]> result.results.bindings
|
const bindings = <LanguageSpecResult[]>result.results.bindings
|
||||||
|
|
||||||
const zh_hant = await fetchSpecial(18130932, "zh_Hant")
|
const zh_hant = await fetchSpecial(18130932, "zh_Hant")
|
||||||
const zh_hans = await fetchSpecial(13414913, "zh_Hant")
|
const zh_hans = await fetchSpecial(13414913, "zh_Hant")
|
||||||
const pt_br = await fetchSpecial(750553, "pt_BR")
|
const pt_br = await fetchSpecial(750553, "pt_BR")
|
||||||
const punjabi = await fetchSpecial(58635, "pa_PK")
|
const punjabi = await fetchSpecial(58635, "pa_PK")
|
||||||
const Shahmukhi = await Wikidata.LoadWikidataEntryAsync(133800)
|
const Shahmukhi = await Wikidata.LoadWikidataEntryAsync(133800)
|
||||||
|
punjabi.forEach((item) => {
|
||||||
punjabi.forEach(item => {
|
const neededLanguage = item.label["xml:lang"]
|
||||||
const native = Shahmukhi.find(item => item.label["xml:lang"] == item.label["xml:lang"]) ??"Shahmukhi";
|
const native = Shahmukhi.labels.get(neededLanguage) ?? Shahmukhi.labels.get("en")
|
||||||
return item.label.value = item.label + " (" +native+")";
|
item.label.value = item.label.value + " (" + native + ")"
|
||||||
})
|
})
|
||||||
|
|
||||||
const fil = await fetchSpecial(33298, "fil")
|
const fil = await fetchSpecial(33298, "fil")
|
||||||
|
|
||||||
|
@ -77,19 +77,21 @@ async function fetchRegularLanguages() {
|
||||||
* @param id
|
* @param id
|
||||||
* @param code
|
* @param code
|
||||||
*/
|
*/
|
||||||
async function fetchSpecial(id: number, code: string) : Promise< LanguageSpecResult []> {
|
async function fetchSpecial(id: number, code: string): Promise<LanguageSpecResult[]> {
|
||||||
ScriptUtils.fixUtils()
|
ScriptUtils.fixUtils()
|
||||||
console.log("Fetching languages")
|
console.log("Fetching languages")
|
||||||
|
|
||||||
const lang = " wd:Q" + id;
|
const lang = " wd:Q" + id
|
||||||
const sparql =
|
const sparql =
|
||||||
"SELECT ?label ?directionalityLabel \n" +
|
"SELECT ?label ?directionalityLabel \n" +
|
||||||
"WHERE \n" +
|
"WHERE \n" +
|
||||||
"{ \n" +
|
"{ \n" +
|
||||||
lang + " rdfs:label ?label." +
|
lang +
|
||||||
lang+ " wdt:P282 ?writing_system. \n" +
|
" rdfs:label ?label." +
|
||||||
|
lang +
|
||||||
|
" wdt:P282 ?writing_system. \n" +
|
||||||
" ?writing_system wdt:P1406 ?directionality. \n" +
|
" ?writing_system wdt:P1406 ?directionality. \n" +
|
||||||
' SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } \n'+
|
' SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } \n' +
|
||||||
"} "
|
"} "
|
||||||
console.log("Special sparql:", sparql)
|
console.log("Special sparql:", sparql)
|
||||||
const url = wds.sparqlQuery(sparql)
|
const url = wds.sparqlQuery(sparql)
|
||||||
|
@ -196,6 +198,6 @@ async function main(wipeCache = false) {
|
||||||
writeFileSync("./assets/language_translations.json", JSON.stringify(translations, null, " "))
|
writeFileSync("./assets/language_translations.json", JSON.stringify(translations, null, " "))
|
||||||
}
|
}
|
||||||
|
|
||||||
const forceRefresh = true || process.argv[2] === "--force-refresh"
|
const forceRefresh = process.argv[2] === "--force-refresh"
|
||||||
ScriptUtils.fixUtils()
|
ScriptUtils.fixUtils()
|
||||||
main(forceRefresh).then(() => console.log("Done!"))
|
main(forceRefresh).then(() => console.log("Done!"))
|
||||||
|
|
Loading…
Reference in a new issue