Add missing languages

This commit is contained in:
pietervdvn 2022-02-25 01:50:15 +01:00
parent 7e5d9fb720
commit 1dbef00fc0
2 changed files with 21 additions and 4 deletions

View file

@ -779,11 +779,11 @@ In the case that MapComplete is pointed to the testing grounds, the edit will be
} }
public static MapToObj<T>(d : Map<string, T>, onValue: ((t:T) => any) = undefined): object{ public static MapToObj<T>(d : Map<string, T>, onValue: ((t:T, key: string) => any) = undefined): object{
const o = {} const o = {}
d.forEach((value, key) => { d.forEach((value, key) => {
if(onValue !== undefined){ if(onValue !== undefined){
value = onValue(value) value = onValue(value, key)
} }
o[key] = value; o[key] = value;
}) })

View file

@ -6,7 +6,7 @@ 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 * as used_languages from "../assets/generated/used_languages.json"
const languageRemap = { const languageRemap = {
// MapComplete (or weblate) on the left, language of wikimedia on the right // MapComplete (or weblate) on the left, language of wikimedia on the right
"nb":"nb_NO", "nb":"nb_NO",
@ -15,6 +15,8 @@ const languageRemap = {
"pt-br":"pt_BR" "pt-br":"pt_BR"
} }
const usedLanguages : Set<string> = new Set(used_languages.languages)
async function fetch(target: string){ async function fetch(target: string){
const regular = await fetchRegularLanguages() const regular = await fetchRegularLanguages()
writeFileSync(target, JSON.stringify(regular, null, " ")) writeFileSync(target, JSON.stringify(regular, null, " "))
@ -92,6 +94,9 @@ function extract(data){
function getNativeList(langs: Map<string, Map<string, string>>){ function getNativeList(langs: Map<string, Map<string, string>>){
const native = {} const native = {}
langs.forEach((translations, key ) =>{ langs.forEach((translations, key ) =>{
if(!usedLanguages.has(key)){
return
}
native[key] = translations.get(key) native[key] = translations.get(key)
}) })
return native return native
@ -111,8 +116,20 @@ async function main(wipeCache = false){
writeFileSync("./assets/language_native.json", JSON.stringify(nativeList, null, " ")) writeFileSync("./assets/language_native.json", JSON.stringify(nativeList, null, " "))
const translations = Utils.MapToObj<Map<string, string>>(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", writeFileSync("./assets/language_translations.json",
JSON.stringify(Utils.MapToObj<Map<string, string>>(perId, value => Utils.MapToObj(value)), null, " ")) JSON.stringify(translations, null, " "))
} }
const forceRefresh = process.argv[2] === "--force-refresh" const forceRefresh = process.argv[2] === "--force-refresh"