forked from MapComplete/MapComplete
Playing around with translatiosn
This commit is contained in:
parent
6f8c29d401
commit
fd6f77c98e
7 changed files with 54 additions and 36 deletions
|
@ -1,6 +1,8 @@
|
||||||
import {LayerDefinition} from "./LayerDefinition";
|
import {LayerDefinition} from "./LayerDefinition";
|
||||||
import { UIElement } from "../UI/UIElement";
|
import { UIElement } from "../UI/UIElement";
|
||||||
import { FixedUiElement } from "../UI/Base/FixedUiElement";
|
import {FixedUiElement} from "../UI/Base/FixedUiElement";
|
||||||
|
import Translation from "../UI/i18n/Translation";
|
||||||
|
import Translations from "../UI/i18n/Translations";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A layout is a collection of settings of the global view (thus: welcome text, title, selection of layers).
|
* A layout is a collection of settings of the global view (thus: welcome text, title, selection of layers).
|
||||||
|
@ -10,14 +12,14 @@ export class Layout {
|
||||||
public title: UIElement;
|
public title: UIElement;
|
||||||
public layers: LayerDefinition[];
|
public layers: LayerDefinition[];
|
||||||
public welcomeMessage: UIElement;
|
public welcomeMessage: UIElement;
|
||||||
public gettingStartedPlzLogin: string;
|
public gettingStartedPlzLogin: UIElement;
|
||||||
public welcomeBackMessage: string;
|
public welcomeBackMessage: UIElement;
|
||||||
|
public welcomeTail: UIElement;
|
||||||
|
|
||||||
public startzoom: number;
|
public startzoom: number;
|
||||||
public supportedLanguages: string[];
|
public supportedLanguages: string[];
|
||||||
public startLon: number;
|
public startLon: number;
|
||||||
public startLat: number;
|
public startLat: number;
|
||||||
public welcomeTail: string;
|
|
||||||
|
|
||||||
public locationContains: string[];
|
public locationContains: string[];
|
||||||
|
|
||||||
|
@ -43,21 +45,21 @@ export class Layout {
|
||||||
startLat: number,
|
startLat: number,
|
||||||
startLon: number,
|
startLon: number,
|
||||||
welcomeMessage: UIElement | string,
|
welcomeMessage: UIElement | string,
|
||||||
gettingStartedPlzLogin: string = "Please login to get started",
|
gettingStartedPlzLogin: UIElement | string = "Please login to get started",
|
||||||
welcomeBackMessage: string = "You are logged in. Welcome back!",
|
welcomeBackMessage: UIElement | string = "You are logged in. Welcome back!",
|
||||||
welcomeTail: string = ""
|
welcomeTail: UIElement | string = ""
|
||||||
) {
|
) {
|
||||||
this.supportedLanguages = supportedLanguages;
|
this.supportedLanguages = supportedLanguages;
|
||||||
this.title = typeof(title) === 'string' ? new FixedUiElement(title) : title;
|
this.title = typeof (title) === 'string' ? new FixedUiElement(title) : title;
|
||||||
this.startLon = startLon;
|
this.startLon = startLon;
|
||||||
this.startLat = startLat;
|
this.startLat = startLat;
|
||||||
this.startzoom = startzoom;
|
this.startzoom = startzoom;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.layers = layers;
|
this.layers = layers;
|
||||||
this.welcomeMessage = typeof(welcomeMessage) === 'string' ? new FixedUiElement(welcomeMessage) : welcomeMessage;
|
this.welcomeMessage =Translations.W(welcomeMessage)
|
||||||
this.gettingStartedPlzLogin = gettingStartedPlzLogin;
|
this.gettingStartedPlzLogin = Translations.W(gettingStartedPlzLogin);
|
||||||
this.welcomeBackMessage = welcomeBackMessage;
|
this.welcomeBackMessage = Translations.W(welcomeBackMessage);
|
||||||
this.welcomeTail = welcomeTail;
|
this.welcomeTail = Translations.W(welcomeTail);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ import {GhostBike} from "../Layers/GhostBike";
|
||||||
import Translations from "../../UI/i18n/Translations";
|
import Translations from "../../UI/i18n/Translations";
|
||||||
import {DrinkingWater} from "../Layers/DrinkingWater";
|
import {DrinkingWater} from "../Layers/DrinkingWater";
|
||||||
import {BikeShop} from "../Layers/BikeShop"
|
import {BikeShop} from "../Layers/BikeShop"
|
||||||
|
import Combine from "../../UI/Base/Combine";
|
||||||
|
|
||||||
|
|
||||||
export default class Cyclofix extends Layout {
|
export default class Cyclofix extends Layout {
|
||||||
|
@ -18,10 +19,13 @@ export default class Cyclofix extends Layout {
|
||||||
16,
|
16,
|
||||||
50.8465573,
|
50.8465573,
|
||||||
4.3516970,
|
4.3516970,
|
||||||
"<h3>" + Translations.t.cyclofix.title.Render() + "</h3>\n" +
|
new Combine([
|
||||||
"\n" +
|
"<h3>",
|
||||||
`<p>${Translations.t.cyclofix.description.Render()}</p>`
|
Translations.t.cyclofix.title,
|
||||||
,
|
"</h3><br/><p>",
|
||||||
|
Translations.t.cyclofix.description,
|
||||||
|
"</p>"
|
||||||
|
]),
|
||||||
"", "");
|
"", "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,8 +18,8 @@ export default class BikeStationOperator extends TagRenderingOptions {
|
||||||
],
|
],
|
||||||
freeform: {
|
freeform: {
|
||||||
key: "operator",
|
key: "operator",
|
||||||
template: to.template,
|
template: to.template.txt,
|
||||||
renderTemplate: to.render,
|
renderTemplate: to.render.txt,
|
||||||
placeholder: "organisatie"
|
placeholder: "organisatie"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
19
UI/Base/Combine.ts
Normal file
19
UI/Base/Combine.ts
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
import {UIElement} from "../UIElement";
|
||||||
|
import Translations from "../i18n/Translations";
|
||||||
|
|
||||||
|
export default class Combine extends UIElement {
|
||||||
|
private uiElements: UIElement[];
|
||||||
|
|
||||||
|
constructor(uiElements: (string | UIElement)[]) {
|
||||||
|
super(undefined);
|
||||||
|
this.uiElements = uiElements.map(Translations.W);
|
||||||
|
}
|
||||||
|
|
||||||
|
InnerRender(): string {
|
||||||
|
let elements = "";
|
||||||
|
for (const element of this.uiElements) {
|
||||||
|
elements += element.Render();
|
||||||
|
}
|
||||||
|
return elements;
|
||||||
|
}
|
||||||
|
}
|
|
@ -13,18 +13,23 @@ export abstract class UIElement {
|
||||||
this.id = "ui-element-" + UIElement.nextId;
|
this.id = "ui-element-" + UIElement.nextId;
|
||||||
this._source = source;
|
this._source = source;
|
||||||
UIElement.nextId++;
|
UIElement.nextId++;
|
||||||
|
if (UIElement.nextId % 100 == 0) {
|
||||||
|
|
||||||
|
console.log(UIElement.nextId)
|
||||||
|
}
|
||||||
this.ListenTo(source);
|
this.ListenTo(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public ListenTo(source: UIEventSource<any>) {
|
public ListenTo(source: UIEventSource<any>) {
|
||||||
if (source === undefined) {
|
if (source === undefined) {
|
||||||
return;
|
return this;
|
||||||
}
|
}
|
||||||
const self = this;
|
const self = this;
|
||||||
source.addCallback(() => {
|
source.addCallback(() => {
|
||||||
self.Update();
|
self.Update();
|
||||||
})
|
})
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onClick: () => void;
|
private _onClick: () => void;
|
||||||
|
|
|
@ -243,7 +243,7 @@ form {
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
margin-left: 2em;
|
margin-left: 2em;
|
||||||
margin-top: 0.5em;
|
margin-top: 3em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#messagesbox-wrapper {
|
#messagesbox-wrapper {
|
||||||
|
|
20
index.ts
20
index.ts
|
@ -164,7 +164,6 @@ const bm = new Basemap("leafletDiv", locationControl, new VariableUiElement(
|
||||||
|
|
||||||
|
|
||||||
// ------------- Setup the layers -------------------------------
|
// ------------- Setup the layers -------------------------------
|
||||||
const controls = {};
|
|
||||||
const addButtons: {
|
const addButtons: {
|
||||||
name: string,
|
name: string,
|
||||||
icon: string,
|
icon: string,
|
||||||
|
@ -194,8 +193,6 @@ for (const layer of layoutToUse.layers) {
|
||||||
|
|
||||||
const flayer = layer.asLayer(bm, allElements, changes, osmConnection.userDetails, selectedElement, generateInfo);
|
const flayer = layer.asLayer(bm, allElements, changes, osmConnection.userDetails, selectedElement, generateInfo);
|
||||||
|
|
||||||
controls[layer.name] = flayer.isDisplayed;
|
|
||||||
|
|
||||||
const addButton = {
|
const addButton = {
|
||||||
name: layer.name,
|
name: layer.name,
|
||||||
icon: layer.icon,
|
icon: layer.icon,
|
||||||
|
@ -272,17 +269,17 @@ new CollapseButton("messagesbox")
|
||||||
var generateWelcomeMessage = () => {
|
var generateWelcomeMessage = () => {
|
||||||
return new VariableUiElement(
|
return new VariableUiElement(
|
||||||
osmConnection.userDetails.map((userdetails) => {
|
osmConnection.userDetails.map((userdetails) => {
|
||||||
var login = layoutToUse.gettingStartedPlzLogin;
|
var login = layoutToUse.gettingStartedPlzLogin.Render();
|
||||||
if (userdetails.loggedIn) {
|
if (userdetails.loggedIn) {
|
||||||
login = layoutToUse.welcomeBackMessage;
|
login = layoutToUse.welcomeBackMessage.Render();
|
||||||
}
|
}
|
||||||
return "<div id='welcomeMessage'>" +
|
return "<div id='welcomeMessage'>" +
|
||||||
layoutToUse.welcomeMessage.Render() + login + layoutToUse.welcomeTail +
|
layoutToUse.welcomeMessage.Render() + login + layoutToUse.welcomeTail.Render() +
|
||||||
"</div>";
|
"</div>";
|
||||||
}),
|
}),
|
||||||
function () {
|
function () {
|
||||||
osmConnection.registerActivateOsmAUthenticationClass()
|
osmConnection.registerActivateOsmAUthenticationClass()
|
||||||
});
|
}).ListenTo(Locale.language);
|
||||||
}
|
}
|
||||||
generateWelcomeMessage().AttachTo("messagesbox");
|
generateWelcomeMessage().AttachTo("messagesbox");
|
||||||
fullScreenMessage.setData(generateWelcomeMessage());
|
fullScreenMessage.setData(generateWelcomeMessage());
|
||||||
|
@ -314,12 +311,3 @@ new GeoLocationHandler(bm).AttachTo("geolocate-button");
|
||||||
|
|
||||||
locationControl.ping();
|
locationControl.ping();
|
||||||
messageBox.update();
|
messageBox.update();
|
||||||
|
|
||||||
/*
|
|
||||||
const eLanguageSelect = document.getElementById('language-select') as HTMLOptionElement
|
|
||||||
eLanguageSelect.addEventListener('input', e => {
|
|
||||||
// @ts-ignore
|
|
||||||
const selectedLanguage = e.target.value as string
|
|
||||||
Locale.language.setData(selectedLanguage.toLowerCase())
|
|
||||||
})
|
|
||||||
*/
|
|
Loading…
Add table
Add a link
Reference in a new issue