forked from MapComplete/MapComplete
Last finishing touches for the opening-hours visualization
This commit is contained in:
parent
895ec01213
commit
35bd49e5ba
13 changed files with 487 additions and 97 deletions
|
@ -8,7 +8,7 @@ export default class Translation extends UIElement {
|
|||
|
||||
private static forcedLanguage = undefined;
|
||||
|
||||
public Subs(text: any) {
|
||||
public Subs(text: any): Translation {
|
||||
const newTranslations = {};
|
||||
for (const lang in this.translations) {
|
||||
let template: string = this.translations[lang];
|
||||
|
@ -16,7 +16,7 @@ export default class Translation extends UIElement {
|
|||
const combined = [];
|
||||
const parts = template.split("{" + k + "}");
|
||||
const el: string | UIElement = text[k];
|
||||
if(el === undefined){
|
||||
if (el === undefined) {
|
||||
continue;
|
||||
}
|
||||
let rtext: string = "";
|
||||
|
@ -40,9 +40,35 @@ export default class Translation extends UIElement {
|
|||
|
||||
}
|
||||
|
||||
public EvaluateSpecialComponents(knownSpecials: { funcName: string, constr: ((call: string) => UIElement) }[]): UIElement {
|
||||
const newTranslations = {};
|
||||
for (const lang in this.translations) {
|
||||
let template: string = this.translations[lang];
|
||||
|
||||
for (const knownSpecial of knownSpecials) {
|
||||
|
||||
|
||||
const combined = [];
|
||||
const matched = template.match(`(.*){${knownSpecial.funcName}\\((.*)\\)}(.*)`);
|
||||
if (matched === null) {
|
||||
continue;
|
||||
}
|
||||
const partBefore = matched[1];
|
||||
const argument = matched[2];
|
||||
const partAfter = matched[3];
|
||||
|
||||
const element = knownSpecial.constr(argument).Render();
|
||||
|
||||
template = partBefore + element + partAfter;
|
||||
}
|
||||
newTranslations[lang] = template;
|
||||
}
|
||||
return new Translation(newTranslations);
|
||||
}
|
||||
|
||||
|
||||
get txt(): string {
|
||||
if(this.translations["*"]){
|
||||
if (this.translations["*"]) {
|
||||
return this.translations["*"];
|
||||
}
|
||||
const txt = this.translations[Translation.forcedLanguage ?? Locale.language.data];
|
||||
|
@ -60,6 +86,7 @@ export default class Translation extends UIElement {
|
|||
return undefined;
|
||||
}
|
||||
|
||||
|
||||
InnerRender(): string {
|
||||
return this.txt
|
||||
}
|
||||
|
|
|
@ -888,14 +888,34 @@ export default class Translations {
|
|||
"en":"During a public holiday, this amenity is"
|
||||
}),
|
||||
opensAt: new T({
|
||||
"en":"from",
|
||||
"nl":"vanaf"
|
||||
}),openTill: new T({
|
||||
"en":"till",
|
||||
"nl":"tot"
|
||||
"en": "from",
|
||||
"nl": "vanaf"
|
||||
}), openTill: new T({
|
||||
"en": "till",
|
||||
"nl": "tot"
|
||||
}),
|
||||
not_all_rules_parsed: new T({
|
||||
"en":"The openin hours of this shop are complicated. The following rules are ignored in the input element:"
|
||||
"en": "The openin hours of this shop are complicated. The following rules are ignored in the input element:"
|
||||
}),
|
||||
closed_until: new T({
|
||||
"en": "Closed until {date}",
|
||||
"nl": "Gesloten - open op {date}"
|
||||
}),
|
||||
|
||||
closed_permanently: new T({
|
||||
"en": "Closed - no opening day known",
|
||||
"nl": "Gesloten"
|
||||
}),
|
||||
ph_not_known: new T({
|
||||
"en": "unknown",
|
||||
"nl": "niet gekend"
|
||||
}),
|
||||
ph_closed: new T({
|
||||
"en": "closed",
|
||||
"nl": "gesloten"
|
||||
}), ph_open: new T({
|
||||
"en": "opened",
|
||||
"nl": "open"
|
||||
})
|
||||
|
||||
|
||||
|
@ -952,7 +972,10 @@ export default class Translations {
|
|||
if (typeof (s) === "string") {
|
||||
return new Translation({en: s});
|
||||
}
|
||||
return s;
|
||||
if (s instanceof Translation) {
|
||||
return s;
|
||||
}
|
||||
throw "??? Not a valid translation"
|
||||
}
|
||||
|
||||
public static CountTranslations() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue