forked from MapComplete/MapComplete
		
	Add missing languages
This commit is contained in:
		
							parent
							
								
									7e5d9fb720
								
							
						
					
					
						commit
						1dbef00fc0
					
				
					 2 changed files with 21 additions and 4 deletions
				
			
		|  | @ -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<string> = 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<string, Map<string, string>>){ | ||||
|     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<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" | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue