Update themes to use new language_chooser

This commit is contained in:
Pieter Vander Vennet 2022-10-29 03:05:29 +02:00
parent 84eee064b2
commit 112b9cd25d
10 changed files with 11077 additions and 40761 deletions

View file

@ -16,11 +16,11 @@ export default class WikidataUtils {
* @param remapLanguages
*/
public static extractLanguageData(
data: { lang: { value: string }; code: { value: string }; label: { value: string } }[],
data: { lang: { value: string }; code: { value: string }; label: { value: string }; directionalityLabel?: { value?: string } }[],
remapLanguages: Record<string, string>
): Map<string, Map<string, string>> {
): Map<string, { translations: Map<string, string>, directionality?: string[] }> {
console.log("Got " + data.length + " entries")
const perId = new Map<string, Map<string, string>>()
const perId = new Map<string, { translations: Map<string, string>, directionality?: string[] }>()
for (const element of data) {
let id = element.code.value
id = remapLanguages[id] ?? id
@ -28,9 +28,16 @@ export default class WikidataUtils {
labelLang = remapLanguages[labelLang] ?? labelLang
const value = element.label.value
if (!perId.has(id)) {
perId.set(id, new Map<string, string>())
perId.set(id, {translations: new Map<string, string>(), directionality: []})
}
const entry = perId.get(id)
entry.translations.set(labelLang, value)
const dir = element.directionalityLabel?.value
if (dir) {
if(entry.directionality.indexOf(dir) < 0) {
entry.directionality.push(dir)
}
}
perId.get(id).set(labelLang, value)
}
console.log("Got " + perId.size + " languages")