From 1dbef00fc0fcfbb1904eaba52d946380d3a60829 Mon Sep 17 00:00:00 2001 From: pietervdvn Date: Fri, 25 Feb 2022 01:50:15 +0100 Subject: [PATCH] Add missing languages --- Utils.ts | 4 ++-- scripts/fetchLanguages.ts | 21 +++++++++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/Utils.ts b/Utils.ts index 28af351b2..1bb9292e3 100644 --- a/Utils.ts +++ b/Utils.ts @@ -779,11 +779,11 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be } - public static MapToObj(d : Map, onValue: ((t:T) => any) = undefined): object{ + public static MapToObj(d : Map, onValue: ((t:T, key: string) => any) = undefined): object{ const o = {} d.forEach((value, key) => { if(onValue !== undefined){ - value = onValue(value) + value = onValue(value, key) } o[key] = value; }) diff --git a/scripts/fetchLanguages.ts b/scripts/fetchLanguages.ts index b9120633b..2abf82e8f 100644 --- a/scripts/fetchLanguages.ts +++ b/scripts/fetchLanguages.ts @@ -6,7 +6,7 @@ import * as wds from "wikidata-sdk" import {Utils} from "../Utils"; import ScriptUtils from "./ScriptUtils"; import {existsSync, readFileSync, writeFileSync} from "fs"; - +import * as used_languages from "../assets/generated/used_languages.json" const languageRemap = { // MapComplete (or weblate) on the left, language of wikimedia on the right "nb":"nb_NO", @@ -15,6 +15,8 @@ const languageRemap = { "pt-br":"pt_BR" } +const usedLanguages : Set = new Set(used_languages.languages) + async function fetch(target: string){ const regular = await fetchRegularLanguages() writeFileSync(target, JSON.stringify(regular, null, " ")) @@ -92,6 +94,9 @@ function extract(data){ function getNativeList(langs: Map>){ const native = {} langs.forEach((translations, key ) =>{ + if(!usedLanguages.has(key)){ + return + } native[key] = translations.get(key) }) return native @@ -111,8 +116,20 @@ async function main(wipeCache = false){ writeFileSync("./assets/language_native.json", JSON.stringify(nativeList, null, " ")) + const translations = Utils.MapToObj>(perId, (value, key) => { + if(!usedLanguages.has(key)){ + return undefined // Remove unused languages + } + return Utils.MapToObj(value, (v, k ) => { + if(!usedLanguages.has(k)){ + return undefined + } + return v + }) + }) + writeFileSync("./assets/language_translations.json", - JSON.stringify(Utils.MapToObj>(perId, value => Utils.MapToObj(value)), null, " ")) + JSON.stringify(translations, null, " ")) } const forceRefresh = process.argv[2] === "--force-refresh"