Merge branch 'develop'

This commit is contained in:
Pieter Vander Vennet 2022-04-21 12:49:24 +02:00
commit dbe53afb49
11 changed files with 69 additions and 62 deletions

View file

@ -191,7 +191,7 @@ export default class SimpleAddUI extends Toggle {
preset.icon(),
new Combine([
title.SetClass("font-bold"),
Translations.WT(preset.description)?.FirstSentence()
preset.description?.FirstSentence()
]).SetClass("flex flex-col")
)
}

View file

@ -202,7 +202,7 @@ export default class DeleteWizard extends Toggle {
private static generateDeleteTagRenderingConfig(softDeletionTags: TagsFilter,
nonDeleteOptions: { if: TagsFilter; then: Translation }[],
extraDeleteReasons: { explanation: Translation; changesetMessage: string }[],
currentTags: any) {
currentTags: any): TagRenderingConfig {
const t = Translations.t.delete
nonDeleteOptions = nonDeleteOptions ?? []
let softDeletionTagsStr = []

View file

@ -613,7 +613,7 @@ export class ImportPointButton extends AbstractImportButton {
icon: () => new Img(args.icon),
layerToAddTo: state.filteredLayers.data.filter(l => l.layerDef.id === args.targetLayer)[0],
name: args.text,
title: Translations.WT(args.text),
title: Translations.T(args.text),
preciseInput: preciseInputSpec, // must be explicitely assigned, if 'undefined' won't work otherwise
boundsFactor: 3
}

View file

@ -86,7 +86,7 @@ export default class MoveWizard extends Toggle {
moveReason.setData(reason)
moveButton = new SubtleButton(
reason.icon.SetStyle("height: 1.5rem; width: 1.5rem;"),
Translations.WT(reason.invitingText)
Translations.T(reason.invitingText)
).onClick(() => {
currentStep.setData("pick_location")
})

View file

@ -207,7 +207,7 @@ export default class TagRenderingQuestion extends Combine {
applicableMappings.map((mapping, i) => {
return {
value: new And([mapping.if, ...allIfNotsExcept(i)]),
shown: Translations.WT(mapping.then)
shown: Translations.T(mapping.then)
}
})
)

View file

@ -22,6 +22,25 @@ export default class Translations {
return s;
}
/**
* Converts a string or an object into a typed translation.
* Translation objects ('Translation' and 'TypedTranslation') are converted/returned
*
* Translations.T("some text") // => new TypedTranslation({"*": "some text"})
* Translations.T("some text").txt // => "some text"
*
* const t = new Translation({"nl": "vertaling", "en": "translation"})
* Translations.T(t) // => new TypedTranslation<object>({"nl": "vertaling", "en": "translation"})
*
* const t = new TypedTranslation({"nl": "vertaling", "en": "translation"})
* Translations.T(t) // => t
*
* const json: any = {"en": "English", "nl": "Nederlands"};
* const translation = Translations.T(new Translation(json));
* translation.textFor("en") // => "English"
* translation.textFor("nl") // => "Nederlands"
*
*/
static T(t: string | any, context = undefined): TypedTranslation<object> {
if (t === undefined || t === null) {
return undefined;
@ -30,7 +49,7 @@ export default class Translations {
t = "" + t
}
if (typeof t === "string") {
return new TypedTranslation({"*": t}, context);
return new TypedTranslation<object>({"*": t}, context);
}
if (t.render !== undefined) {
const msg = "Creating a translation, but this object contains a 'render'-field. Use the translation directly"
@ -40,30 +59,12 @@ export default class Translations {
if (t instanceof TypedTranslation) {
return t;
}
return new TypedTranslation(t, context);
if(t instanceof Translation){
return new TypedTranslation<object>(t.translations)
}
return new TypedTranslation<object>(t, context);
}
/**
* 'Wrap Translation': given an object containing translations OR a string, returns a translation object
*
* const json: any = {"en": "English", "nl": "Nederlands"};
* const translation = Translations.WT(new Translation(json));
* translation.textFor("en") // => "English"
* translation.textFor("nl") // => "Nederlands"
*/
public static WT(s: string | Translation): Translation {
if (s === undefined || s === null) {
return undefined;
}
if (typeof (s) === "string") {
return new Translation({'*': s});
}
if (s instanceof Translation) {
return s.Clone() /* MUST CLONE HERE! */;
}
console.error("Trying to Translation.WT, but got ", s)
throw "??? Not a valid translation"
}
public static CountTranslations() {
const queue: any = [Translations.t];