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

@ -1,13 +1,15 @@
import {UIEventSource} from "../Logic/UIEventSource"; import {UIEventSource} from "../Logic/UIEventSource";
import BaseUIElement from "./BaseUIElement"; import BaseUIElement from "./BaseUIElement";
import FeaturePipelineState from "../Logic/State/FeaturePipelineState";
import {DefaultGuiState} from "./DefaultGuiState";
export interface SpecialVisualization { export interface SpecialVisualization {
funcName: string funcName: string
constr: ( constr: (
state: any, /*FeaturePipelineState*/ state: FeaturePipelineState,
tagSource: UIEventSource<any>, tagSource: UIEventSource<any>,
argument: string[], argument: string[],
guistate: any /*DefaultGuiState*/ guistate: DefaultGuiState
) => BaseUIElement ) => BaseUIElement
docs: string | BaseUIElement docs: string | BaseUIElement
example?: string example?: string

View file

@ -51,6 +51,7 @@ import LayerConfig from "../Models/ThemeConfig/LayerConfig";
import {GeoOperations} from "../Logic/GeoOperations"; import {GeoOperations} from "../Logic/GeoOperations";
import StatisticsPanel from "./BigComponents/StatisticsPanel"; import StatisticsPanel from "./BigComponents/StatisticsPanel";
import AutoApplyButton from "./Popup/AutoApplyButton"; import AutoApplyButton from "./Popup/AutoApplyButton";
import {LanguageElement} from "./Popup/LanguageElement";
export default class SpecialVisualizations { export default class SpecialVisualizations {
public static specialVisualizations: SpecialVisualization[] = SpecialVisualizations.initList(); public static specialVisualizations: SpecialVisualization[] = SpecialVisualizations.initList();
@ -74,6 +75,7 @@ export default class SpecialVisualizations {
new CloseNoteButton(), new CloseNoteButton(),
new NearbyImageVis(), new NearbyImageVis(),
new MapillaryLinkVis(), new MapillaryLinkVis(),
new LanguageElement(),
{ {
funcName: "all_tags", funcName: "all_tags",
docs: "Prints all key-value pairs of the object - used for debugging", docs: "Prints all key-value pairs of the object - used for debugging",

View file

@ -16,11 +16,11 @@ export default class WikidataUtils {
* @param remapLanguages * @param remapLanguages
*/ */
public static extractLanguageData( 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> remapLanguages: Record<string, string>
): Map<string, Map<string, string>> { ): Map<string, { translations: Map<string, string>, directionality?: string[] }> {
console.log("Got " + data.length + " entries") 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) { for (const element of data) {
let id = element.code.value let id = element.code.value
id = remapLanguages[id] ?? id id = remapLanguages[id] ?? id
@ -28,9 +28,16 @@ export default class WikidataUtils {
labelLang = remapLanguages[labelLang] ?? labelLang labelLang = remapLanguages[labelLang] ?? labelLang
const value = element.label.value const value = element.label.value
if (!perId.has(id)) { 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") console.log("Got " + perId.size + " languages")

View file

@ -1,5 +1,6 @@
{ {
"ca": "català", "ca": "català",
"cs": "čeština",
"da": "dansk", "da": "dansk",
"de": "Deutsch", "de": "Deutsch",
"en": "English", "en": "English",

File diff suppressed because it is too large Load diff

View file

@ -135,14 +135,21 @@
} }
}, },
"induction-loop", "induction-loop",
{ {"render": {
"builtin": "wikidata.tactile_writing-braille", "id": "tactile_writing_language",
"override": { "special": {
"type": "language_chooser",
"question": { "question": {
"en": "In which languages does this elevator have tactile writing (braille)?" "en": "In which languages does this elevator have tactile writing (braille)?"
},
"render_list_item": {
"en": "This elevator has tactile writing in {language():font-bold}"
},
"render_single_language": {
"en": "This elevator has tactile writing in {language():font-bold}"
} }
} }
} }}
], ],
"mapRendering": [ "mapRendering": [
{ {
@ -218,4 +225,4 @@
] ]
} }
] ]
} }

View file

@ -296,28 +296,31 @@
"phone", "phone",
"email", "email",
{ {
"builtin": "wikidata.school-language", "id": "school-language",
"override": { "render": {
"+mappings": [ "special": {
{ "type": "language_chooser",
"if": "school:language=", "key": "language",
"hideInAnswer": true, "render_all": {
"then": { "en": "The following languages are used in this school:{list()}"
"en": "The main language of this school is unknown", },
"nl": "De voertaal van deze school is niet gekend", "render_single_language": {
"de": "Die Unterrichtssprache der Schule ist unbekannt", "en": "{language():font-bold} is the main language of this school"
"fr": "La langue principale de cette école est inconnue" },
}
}
],
"question": { "question": {
"en": "What is the main language of this school?<div class='subtle'>What language is spoken with the students in non-language related courses and with the administration?</div>", "en": "What is the main language of this school?<div class='subtle'>What language is spoken with the students in non-language related courses and with the administration?</div>",
"nl": "Wat is de voertaal van deze school?<div class='subtle'>Welke taal wordt met de studenten gesproken in niet-taal-gerelateerde vakken en met de administratie?</div>", "nl": "Wat is de voertaal van deze school?<div class='subtle'>Welke taal wordt met de studenten gesproken in niet-taal-gerelateerde vakken en met de administratie?</div>",
"de": "Was ist die Hauptsprache dieser Schule?<div class='subtle'>Welche Sprache wird mit den Schülern in den nicht sprachbezogenen Kursen und mit der Verwaltung gesprochen?</div>", "de": "Was ist die Hauptsprache dieser Schule?<div class='subtle'>Welche Sprache wird mit den Schülern in den nicht sprachbezogenen Kursen und mit der Verwaltung gesprochen?</div>",
"fr": "Quelle est la langue principale de cette école ?<div class='subtle'>Quelle langue est parlée avec les élèves des cours non linguistiques et avec l'administration ?</div>" "fr": "Quelle est la langue principale de cette école ?<div class='subtle'>Quelle langue est parlée avec les élèves des cours non linguistiques et avec l'administration ?</div>"
},
"no_known_languages": {
"en": "The main language of this school is unknown",
"nl": "De voertaal van deze school is niet gekend",
"de": "Die Unterrichtssprache der Schule ist unbekannt",
"fr": "La langue principale de cette école est inconnue"
} }
} }
} }}
], ],
"presets": [ "presets": [
{ {
@ -360,4 +363,4 @@
"width": 1 "width": 1
} }
] ]
} }

View file

@ -50,6 +50,74 @@
} }
] ]
}, },
{
"id": "tactile_writing",
"condition": "handrail=yes",
"question": {
"en": "Do these stairs have tactile writing on the handrail?"
},
"mappings": [
{
"if": "tactile_writing=yes",
"then": {
"en": "There is tactile writing on the handrail"
}
},
{
"if": "tactile_writing=no",
"then": {
"en": "There is no tactile writing on the handrail"
}
}
]
},
{
"id": "tactile_writing_language",
"condition": "tactile_writing:braille:language=yes",
"render": {
"special": {
"type": "language_chooser",
"key": "tactile_writing:braille:language",
"question": {
"en": "In which languages is there tactile writing (braille) for navigation? <img src='./assets/layers/stairs/Braille_stairs.jpg' style='height: 300px; width: auto; display: block;' />"
},
"render_list_item": {
"en": "These stairs have tactile writing in {language():font-bold}"
},
"render_single_language": {
"en": "These stairs have tactile writing in {language():font-bold}"
}
}
}
},
{
"id": "conveying",
"mappings": [
{
"if": "conveying=yes",
"then": {
"en": "This is an escalator",
"nl": "Dit is een roltrap"
}
},
{
"if": "conveying=no",
"then": {
"en": "This is not an escalator",
"nl": "Dit is geen roltrap"
}
},
{
"if": "conveying=",
"then": {
"en": "This is not an escalator",
"nl": "Dit is geen roltrap"
},
"hideInAnswer": true
}
]
},
{ {
"id": "ramp", "id": "ramp",
"question": { "question": {
@ -93,33 +161,6 @@
} }
} }
] ]
},
{
"builtin": "wikidata.tactile_writing-braille",
"override": {
"question": {
"en": "In which languages is there tactile writing (braille) for navigation? <img src='./assets/layers/stairs/Braille_stairs.jpg' style='height: 300px; width: auto; display: block;' />"
}
}
},
{
"id": "conveying",
"mappings": [
{
"if": "conveying=yes",
"then": {
"en": "This is an escalator",
"nl": "Dit is een roltrap"
}
},
{
"if": "conveying=no",
"then": {
"en": "This is not an escalator",
"nl": "Dit is geen roltrap"
}
}
]
} }
], ],
"mapRendering": [ "mapRendering": [
@ -129,4 +170,4 @@
"dashArray": "2 2" "dashArray": "2 2"
} }
] ]
} }

File diff suppressed because it is too large Load diff

24
test.ts
View file

@ -0,0 +1,24 @@
import {LanguageElement} from "./UI/Popup/LanguageElement";
import {ImmutableStore, UIEventSource} from "./Logic/UIEventSource";
import {VariableUiElement} from "./UI/Base/VariableUIElement";
import Locale from "./UI/i18n/Locale";
import {OsmConnection} from "./Logic/Osm/OsmConnection";
const tgs = new UIEventSource({
"name": "xyz",
"id": "node/1234",
"_country" : "BE",
})
Locale.language.setData("nl")
console.log(tgs)
console.log("Locale", Locale.language)
const conn = new OsmConnection({})
new LanguageElement().constr(<any> {osmConnection: conn, featureSwitchIsTesting: new ImmutableStore(true)}, tgs, [
"language",
"What languages are spoken here?",
"{language()} is spoken here",
"{language()} is the only language spoken here",
"The following languages are spoken here: {list()}"
]).AttachTo("maindiv")
new VariableUiElement(tgs.map(JSON.stringify)).AttachTo("extradiv")