Add translation buttons

This commit is contained in:
Pieter Vander Vennet 2022-04-01 12:51:55 +02:00
parent 592bc4ae0b
commit 2c7fb556dc
31 changed files with 442 additions and 150 deletions

View file

@ -11,7 +11,7 @@ export default class ExtraLinkConfig {
constructor(configJson: ExtraLinkConfigJson, context) {
this.icon = configJson.icon
this.text = Translations.T(configJson.text)
this.text = Translations.T(configJson.text, "themes:"+context+".text")
this.href = configJson.href
this.newTab = configJson.newTab
this.requirements = new Set(configJson.requirements)

View file

@ -38,7 +38,7 @@ export default class FilterConfig {
this.id = json.id;
let defaultSelection : number = undefined
this.options = json.options.map((option, i) => {
const ctx = `${context}.options[${i}]`;
const ctx = `${context}.options.${i}`;
const question = Translations.T(
option.question,
`${ctx}.question`

View file

@ -72,6 +72,7 @@ export default class LayerConfig extends WithContextLoader {
official: boolean = true
) {
context = context + "." + json.id;
const translationContext = "layers:"+json.id
super(json, context)
this.id = json.id;
@ -125,7 +126,7 @@ export default class LayerConfig extends WithContextLoader {
this.allowSplit = json.allowSplit ?? false;
this.name = Translations.T(json.name, context + ".name");
this.name = Translations.T(json.name, translationContext + ".name");
this.units = (json.units ?? []).map(((unitJson, i) => Unit.fromJson(unitJson, `${context}.unit[${i}]`)))
if (json.description !== undefined) {
@ -136,7 +137,7 @@ export default class LayerConfig extends WithContextLoader {
this.description = Translations.T(
json.description,
context + ".description"
translationContext + ".description"
);
@ -211,9 +212,9 @@ export default class LayerConfig extends WithContextLoader {
}
const config: PresetConfig = {
title: Translations.T(pr.title, `${context}.presets[${i}].title`),
title: Translations.T(pr.title, `${translationContext}.presets.${i}.title`),
tags: pr.tags.map((t) => TagUtils.SimpleTag(t)),
description: Translations.T(pr.description, `${context}.presets[${i}].description`),
description: Translations.T(pr.description, `${translationContext}.presets.${i}.description`),
preciseInput: preciseInput,
exampleImages: pr.exampleImages
}
@ -258,7 +259,7 @@ export default class LayerConfig extends WithContextLoader {
this.filters = []
} else {
this.filters = (<FilterConfigJson[]>json.filter ?? []).map((option, i) => {
return new FilterConfig(option, `${context}.filter-[${i}]`)
return new FilterConfig(option, `layers:${this.id}.filter.${i}`)
});
}

View file

@ -67,7 +67,11 @@ export default class LayoutConfig {
throw "The id of a theme should match [a-z0-9-_]*: " + json.id
}
}
context = (context ?? "") + "." + this.id;
if(context === undefined){
context = this.id
}else{
context = context + "." + this.id;
}
this.maintainer = json.maintainer;
this.credits = json.credits;
this.version = json.version;
@ -99,10 +103,10 @@ export default class LayoutConfig {
throw "Got undefined layers for " + json.id + " at " + context
}
}
this.title = new Translation(json.title, context + ".title");
this.description = new Translation(json.description, context + ".description");
this.shortDescription = json.shortDescription === undefined ? this.description.FirstSentence() : new Translation(json.shortDescription, context + ".shortdescription");
this.descriptionTail = json.descriptionTail === undefined ? undefined : new Translation(json.descriptionTail, context + ".descriptionTail");
this.title = new Translation(json.title, "themes:"+context + ".title");
this.description = new Translation(json.description, "themes:"+context + ".description");
this.shortDescription = json.shortDescription === undefined ? this.description.FirstSentence() : new Translation(json.shortDescription, "themes:"+context + ".shortdescription");
this.descriptionTail = json.descriptionTail === undefined ? undefined : new Translation(json.descriptionTail, "themes:"+context + ".descriptionTail");
this.icon = json.icon;
this.socialImage = json.socialImage ?? LayoutConfig.defaultSocialImage;
if (this.socialImage === "") {
@ -125,7 +129,7 @@ export default class LayoutConfig {
href: "https://mapcomplete.osm.be/{theme}.html?lat={lat}&lon={lon}&z={zoom}&language={language}",
newTab: true,
requirements: ["iframe","no-welcome-message"]
}, context)
}, context+".extraLink")
this.clustering = {

View file

@ -54,7 +54,6 @@ export default class TagRenderingConfig {
if (json === undefined) {
throw "Initing a TagRenderingConfig with undefined in " + context;
}
if (json === "questions") {
// Very special value
this.render = null;
@ -70,9 +69,23 @@ export default class TagRenderingConfig {
json = "" + json
}
let translationKey = context;
if(json["id"] !== undefined){
const layerId = context.split(".")[0]
if(json["source"]){
let src = json["source"]+":"
if(json["source"] === "shared-questions"){
src += "shared_questions."
}
translationKey = `${src}${json["id"] ?? ""}`
}else{
translationKey = `layers:${layerId}.tagRenderings.${json["id"] ?? ""}`
}
}
if (typeof json === "string") {
this.render = Translations.T(json, context + ".render");
this.render = Translations.T(json, translationKey + ".render");
this.multiAnswer = false;
return;
}
@ -86,8 +99,8 @@ export default class TagRenderingConfig {
this.group = json.group ?? "";
this.labels = json.labels ?? []
this.render = Translations.T(json.render, context + ".render");
this.question = Translations.T(json.question, context + ".question");
this.render = Translations.T(json.render, translationKey + ".render");
this.question = Translations.T(json.question, translationKey + ".question");
this.condition = TagUtils.Tag(json.condition ?? {"and": []}, `${context}.condition`);
if (json.freeform) {
@ -101,7 +114,7 @@ export default class TagRenderingConfig {
const typeDescription = Translations.t.validation[type]?.description
placeholder = Translations.T(json.freeform.key+" ("+type+")")
if(typeDescription !== undefined){
placeholder = placeholder.Fuse(typeDescription, type)
placeholder = placeholder.Subs({[type]: typeDescription})
}
}
@ -155,7 +168,7 @@ export default class TagRenderingConfig {
this.mappings = json.mappings.map((mapping, i) => {
const ctx = `${context}.mapping[${i}]`
const ctx = `${translationKey}.mappings.${i}`
if (mapping.then === undefined) {
throw `${ctx}: Invalid mapping: if without body`
}