Skip to content

Commit

Permalink
Add missing languages
Browse files Browse the repository at this point in the history
  • Loading branch information
pietervdvn committed Feb 25, 2022
1 parent 7e5d9fb commit 1dbef00
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
d.forEach((value, key) => {
if(onValue !== undefined){
value = onValue(value)
value = onValue(value, key)
}
o[key] = value;
})
Expand Down
21 changes: 19 additions & 2 deletions scripts/fetchLanguages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -15,6 +15,8 @@ const languageRemap = {
"pt-br":"pt_BR"
}

const usedLanguages : Set<string> = new Set(used_languages.languages)

async function fetch(target: string){
const regular = await fetchRegularLanguages()
writeFileSync(target, JSON.stringify(regular, null, " "))
Expand Down Expand Up @@ -92,6 +94,9 @@ function extract(data){
function getNativeList(langs: Map<string, Map<string, string>>){
const native = {}
langs.forEach((translations, key ) =>{
if(!usedLanguages.has(key)){
return
}
native[key] = translations.get(key)
})
return native
Expand All @@ -111,8 +116,20 @@ async function main(wipeCache = false){
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",
JSON.stringify(Utils.MapToObj<Map<string, string>>(perId, value => Utils.MapToObj(value)), null, " "))
JSON.stringify(translations, null, " "))
}

const forceRefresh = process.argv[2] === "--force-refresh"
Expand Down

0 comments on commit 1dbef00

Please sign in to comment.