From 0bb5abec3c5c5a393e4869826ae0f8a838724db3 Mon Sep 17 00:00:00 2001 From: Pieter Vander Vennet Date: Wed, 22 Jul 2020 00:18:07 +0200 Subject: [PATCH] More translation fixes, allows re-enabling questions (fix #51) --- Customizations/Layers/BikeStations.ts | 23 +++++------- .../Questions/bike/PumpOperational.ts | 6 +-- Customizations/Questions/bike/PumpValves.ts | 14 +++---- Customizations/Questions/bike/ShopDiy.ts | 6 +-- Customizations/Questions/bike/ShopPump.ts | 6 +-- Customizations/TagRendering.ts | 2 +- UI/FeatureInfoBox.ts | 37 ++++++++++++++++--- UI/i18n/Translation.ts | 4 ++ UI/i18n/Translations.ts | 8 ++++ docs/Create a theme.md | 14 +++++++ 10 files changed, 83 insertions(+), 37 deletions(-) create mode 100644 docs/Create a theme.md diff --git a/Customizations/Layers/BikeStations.ts b/Customizations/Layers/BikeStations.ts index cc9b6eb..5239833 100644 --- a/Customizations/Layers/BikeStations.ts +++ b/Customizations/Layers/BikeStations.ts @@ -62,24 +62,19 @@ export default class BikeStations extends LayerDefinition { const hasPump = self.pump.matchesProperties(properties) const isOperational = self.pumpOperationalOk.matchesProperties(properties) const hasTools = self.tools.matchesProperties(properties) - let iconName = "" - if (hasPump) { - if (hasTools) { - iconName = "repair_station_pump.svg" - } else { - if (isOperational) { - iconName = "pump.svg" - } else { - iconName = "broken_pump.svg" - } - } - } else { - if (!self.pump.matchesProperties(properties)) { + let iconName = "repair_station.svg"; + if (hasTools && hasPump && isOperational) { + iconName = "repair_station_pump.svg" + }else if(hasTools){ iconName = "repair_station.svg" + }else if(hasPump){ + if (isOperational) { + iconName = "pump.svg" } else { - iconName = "repair_station.svg" + iconName = "broken_pump.svg" } } + const iconUrl = `./assets/bike/${iconName}` return { color: "#00bb00", diff --git a/Customizations/Questions/bike/PumpOperational.ts b/Customizations/Questions/bike/PumpOperational.ts index a539b0a..ac84f0c 100644 --- a/Customizations/Questions/bike/PumpOperational.ts +++ b/Customizations/Questions/bike/PumpOperational.ts @@ -7,10 +7,10 @@ export default class PumpOperational extends TagRenderingOptions { constructor() { const to = Translations.t.cyclofix.station.operational super({ - question: to.question.Render(), + question: to.question, mappings: [ - {k: new Tag("service:bicycle:pump:operational_status","broken"), txt: to.broken.txt}, - {k: new Tag("service:bicycle:pump:operational_status",""), txt: to.operational.txt} + {k: new Tag("service:bicycle:pump:operational_status","broken"), txt: to.broken}, + {k: new Tag("service:bicycle:pump:operational_status",""), txt: to.operational} ] }); } diff --git a/Customizations/Questions/bike/PumpValves.ts b/Customizations/Questions/bike/PumpValves.ts index 800a9b3..51247d0 100644 --- a/Customizations/Questions/bike/PumpValves.ts +++ b/Customizations/Questions/bike/PumpValves.ts @@ -7,21 +7,21 @@ export default class PumpValves extends TagRenderingOptions{ constructor() { const to = Translations.t.cyclofix.station.valves super({ - question: to.question.Render(), + question: to.question, mappings: [ { k: new Tag("valves", " sclaverand;schrader;dunlop"), - txt: to.default.Render() + txt: to.default }, - {k: new Tag("valves", "dunlop"), txt: to.dunlop.Render()}, - {k: new Tag("valves", "sclaverand"), txt: to.sclaverand.Render()}, - {k: new Tag("valves", "auto"), txt: to.auto.Render()}, + {k: new Tag("valves", "dunlop"), txt: to.dunlop}, + {k: new Tag("valves", "sclaverand"), txt: to.sclaverand}, + {k: new Tag("valves", "auto"), txt: to.auto}, ], freeform: { extraTags: new Tag("fixme", "Freeform valves= tag used: possibly a wrong value"), key: "valves", - template: to.template.txt, - renderTemplate: to.render.txt + template: to.template, + renderTemplate: to.render } }); } diff --git a/Customizations/Questions/bike/ShopDiy.ts b/Customizations/Questions/bike/ShopDiy.ts index e893114..4821731 100644 --- a/Customizations/Questions/bike/ShopDiy.ts +++ b/Customizations/Questions/bike/ShopDiy.ts @@ -9,10 +9,10 @@ export default class ShopPump extends TagRenderingOptions { const to = Translations.t.cyclofix.shop.diy super({ priority: 5, - question: to.question.Render(), + question: to.question, mappings: [ - {k: new Tag(key, "yes"), txt: to.yes.Render()}, - {k: new Tag(key, "no"), txt: to.no.Render()}, + {k: new Tag(key, "yes"), txt: to.yes}, + {k: new Tag(key, "no"), txt: to.no}, ] }); } diff --git a/Customizations/Questions/bike/ShopPump.ts b/Customizations/Questions/bike/ShopPump.ts index a64f13b..6ed14da 100644 --- a/Customizations/Questions/bike/ShopPump.ts +++ b/Customizations/Questions/bike/ShopPump.ts @@ -9,10 +9,10 @@ export default class ShopPump extends TagRenderingOptions { const to = Translations.t.cyclofix.shop.pump super({ priority: 5, - question: to.question.Render(), + question: to.question, mappings: [ - {k: new Tag(key, "yes"), txt: to.yes.Render()}, - {k: new Tag(key, "no"), txt: to.no.Render()}, + {k: new Tag(key, "yes"), txt: to.yes}, + {k: new Tag(key, "no"), txt: to.no}, ] }); } diff --git a/Customizations/TagRendering.ts b/Customizations/TagRendering.ts index 1544aeb..a426fa3 100644 --- a/Customizations/TagRendering.ts +++ b/Customizations/TagRendering.ts @@ -270,7 +270,7 @@ class TagRendering extends UIElement implements TagDependantUIElement { } else { return ""+Translations.t.general.skip.R()+""; } - }); + }, [Locale.language]); // And at last, set up the skip button this._skipButton = new VariableUiElement(cancelContents).onClick(cancel) ; } diff --git a/UI/FeatureInfoBox.ts b/UI/FeatureInfoBox.ts index 89d7bce..7763410 100644 --- a/UI/FeatureInfoBox.ts +++ b/UI/FeatureInfoBox.ts @@ -11,6 +11,7 @@ import {OsmLink} from "../Customizations/Questions/OsmLink"; import {WikipediaLink} from "../Customizations/Questions/WikipediaLink"; import {And} from "../Logic/TagsFilter"; import {TagDependantUIElement, TagDependantUIElementConstructor} from "../Customizations/UIElementConstructor"; +import Translations from "./i18n/Translations"; export class FeatureInfoBox extends UIElement { @@ -24,10 +25,13 @@ export class FeatureInfoBox extends UIElement { private _wikipedialink: UIElement; - private _infoboxes: TagDependantUIElement[]; private _questions: QuestionPicker; + private _oneSkipped = Translations.t.general.oneSkippedQuestion.Clone(); + private _someSkipped = Translations.t.general.skippedQuestions.Clone(); + + constructor( tagsES: UIEventSource, title: TagRenderingOptions | UIElement, @@ -41,14 +45,28 @@ export class FeatureInfoBox extends UIElement { this._userDetails = userDetails; this.ListenTo(userDetails); - const deps = {tags:this._tagsES , changes:this._changes} - + const deps = {tags: this._tagsES, changes: this._changes} + this._infoboxes = []; elementsToShow = elementsToShow ?? [] + + const self = this; for (const tagRenderingOption of elementsToShow) { - this._infoboxes.push( + self._infoboxes.push( tagRenderingOption.construct(deps)); } + function initTags() { + self._infoboxes = [] + for (const tagRenderingOption of elementsToShow) { + self._infoboxes.push( + tagRenderingOption.construct(deps)); + } + self.Update(); + } + + this._someSkipped.onClick(initTags) + this._oneSkipped.onClick(initTags) + title = title ?? new TagRenderingOptions( { @@ -71,13 +89,16 @@ export class FeatureInfoBox extends UIElement { const info = []; - const questions : TagDependantUIElement[] = []; - + const questions: TagDependantUIElement[] = []; + let skippedQuestions = 0; for (const infobox of this._infoboxes) { if (infobox.IsKnown()) { info.push(infobox); } else if (infobox.IsQuestioning()) { questions.push(infobox); + } else { + // This question is neither known nor questioning -> it was skipped + skippedQuestions++; } } @@ -97,6 +118,10 @@ export class FeatureInfoBox extends UIElement { } questionsHtml = mostImportantQuestion.Render(); + } else if (skippedQuestions == 1) { + questionsHtml = this._oneSkipped.Render(); + } else if (skippedQuestions > 0) { + questionsHtml = this._someSkipped.Render(); } return "
" + diff --git a/UI/i18n/Translation.ts b/UI/i18n/Translation.ts index 2ed7484..c02f842 100644 --- a/UI/i18n/Translation.ts +++ b/UI/i18n/Translation.ts @@ -36,4 +36,8 @@ export default class Translation extends UIElement { return new Translation(this.translations).Render(); } + public Clone(){ + return new Translation(this.translations) + } + } diff --git a/UI/i18n/Translations.ts b/UI/i18n/Translations.ts index b22dd25..b954ac5 100644 --- a/UI/i18n/Translations.ts +++ b/UI/i18n/Translations.ts @@ -372,6 +372,14 @@ export default class Translations { skip: new T({ en: "Skip this question", nl: "Vraag overslaan" + }), + oneSkippedQuestion: new T({ + en: "One question is skipped", + nl: "Een vraag is overgeslaan" + }), + skippedQuestions: new T({ + en: "Some questions are skipped", + nl: "Sommige vragen zijn overgeslaan" }) } } diff --git a/docs/Create a theme.md b/docs/Create a theme.md new file mode 100644 index 0000000..778b98a --- /dev/null +++ b/docs/Create a theme.md @@ -0,0 +1,14 @@ +# Create a theme + + + +A _layer_ is a set of features of a single kind, e.g. 'bookcases'. +A _layout_ is a set of layers, e.g. 'bookcases' + 'nature reserves'. They are shown together with some text on the left. They can be switched with the query parameter 'layout' in the url (thus by going to 'index.html?layout=bookcases') + +If you want to make your own version of MapComplete, you create your own layout + +- Clone the repo +- Build it +- Go into 'Customazations/Layouts' and copy a file there (e.g. bookcases) +- Change the text and layer selection +- Create you layers \ No newline at end of file