forked from MapComplete/MapComplete
Handle metadata in translations
This commit is contained in:
parent
30a835a232
commit
efb54782ca
6 changed files with 47 additions and 24 deletions
|
@ -526,7 +526,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
* // should warn for unexpected keys
|
* // should warn for unexpected keys
|
||||||
* const errors = []
|
* const errors = []
|
||||||
* RewriteSpecial.convertIfNeeded({"special": {type: "image_carousel"}, "en": "xyz"}, errors, "test") // => {'*': "{image_carousel()}"}
|
* RewriteSpecial.convertIfNeeded({"special": {type: "image_carousel"}, "en": "xyz"}, errors, "test") // => {'*': "{image_carousel()}"}
|
||||||
* errors // => ["The only keys allowed next to a 'special'-block are 'before' and 'after'. Perhaps you meant to put 'en' into the special block?"]
|
* errors // => ["At test: The only keys allowed next to a 'special'-block are 'before' and 'after'. Perhaps you meant to put 'en' into the special block?"]
|
||||||
*
|
*
|
||||||
* // should give an error on unknown visualisations
|
* // should give an error on unknown visualisations
|
||||||
* const errors = []
|
* const errors = []
|
||||||
|
@ -593,7 +593,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
...Array.from(Object.keys(input))
|
...Array.from(Object.keys(input))
|
||||||
.filter((k) => k !== "special" && k !== "before" && k !== "after")
|
.filter((k) => k !== "special" && k !== "before" && k !== "after")
|
||||||
.map((k) => {
|
.map((k) => {
|
||||||
return `The only keys allowed next to a 'special'-block are 'before' and 'after'. Perhaps you meant to put '${k}' into the special block?`
|
return `At ${context}: The only keys allowed next to a 'special'-block are 'before' and 'after'. Perhaps you meant to put '${k}' into the special block?`
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -610,7 +610,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
argNamesList,
|
argNamesList,
|
||||||
(x) => x
|
(x) => x
|
||||||
)
|
)
|
||||||
return `Unexpected argument in special block at ${context} with name '${wrongArg}'. Did you mean ${
|
return `At ${context}: Unexpected argument in special block at ${context} with name '${wrongArg}'. Did you mean ${
|
||||||
byDistance[0]
|
byDistance[0]
|
||||||
}?\n\tAll known arguments are ${argNamesList.join(", ")}`
|
}?\n\tAll known arguments are ${argNamesList.join(", ")}`
|
||||||
})
|
})
|
||||||
|
@ -623,7 +623,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
}
|
}
|
||||||
const param = special[arg.name]
|
const param = special[arg.name]
|
||||||
if (param === undefined) {
|
if (param === undefined) {
|
||||||
errors.push(`Obligated parameter '${arg.name}' not found`)
|
errors.push(`At ${context}: Obligated parameter '${arg.name}' in special rendering of type ${vis.funcName} not found.\n${arg.doc}`)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,7 +735,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
Utils.WalkPath(path.path, json, (leaf, travelled) =>
|
Utils.WalkPath(path.path, json, (leaf, travelled) =>
|
||||||
RewriteSpecial.convertIfNeeded(leaf, errors, travelled.join("."))
|
RewriteSpecial.convertIfNeeded(leaf, errors, context + ":" + travelled.join("."))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,19 @@
|
||||||
import { DesugaringStep, Each, Fuse, On } from "./Conversion"
|
import {DesugaringStep, Each, Fuse, On} from "./Conversion"
|
||||||
import { LayerConfigJson } from "../Json/LayerConfigJson"
|
import {LayerConfigJson} from "../Json/LayerConfigJson"
|
||||||
import LayerConfig from "../LayerConfig"
|
import LayerConfig from "../LayerConfig"
|
||||||
import { Utils } from "../../../Utils"
|
import {Utils} from "../../../Utils"
|
||||||
import Constants from "../../Constants"
|
import Constants from "../../Constants"
|
||||||
import { Translation } from "../../../UI/i18n/Translation"
|
import {Translation} from "../../../UI/i18n/Translation"
|
||||||
import { LayoutConfigJson } from "../Json/LayoutConfigJson"
|
import {LayoutConfigJson} from "../Json/LayoutConfigJson"
|
||||||
import LayoutConfig from "../LayoutConfig"
|
import LayoutConfig from "../LayoutConfig"
|
||||||
import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
|
import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson"
|
||||||
import { TagUtils } from "../../../Logic/Tags/TagUtils"
|
import {TagUtils} from "../../../Logic/Tags/TagUtils"
|
||||||
import { ExtractImages } from "./FixImages"
|
import {ExtractImages} from "./FixImages"
|
||||||
import ScriptUtils from "../../../scripts/ScriptUtils"
|
import ScriptUtils from "../../../scripts/ScriptUtils"
|
||||||
import { And } from "../../../Logic/Tags/And"
|
import {And} from "../../../Logic/Tags/And"
|
||||||
import Translations from "../../../UI/i18n/Translations"
|
import Translations from "../../../UI/i18n/Translations"
|
||||||
import Svg from "../../../Svg"
|
import Svg from "../../../Svg"
|
||||||
import { QuestionableTagRenderingConfigJson } from "../Json/QuestionableTagRenderingConfigJson"
|
import {QuestionableTagRenderingConfigJson} from "../Json/QuestionableTagRenderingConfigJson"
|
||||||
import FilterConfigJson from "../Json/FilterConfigJson"
|
import FilterConfigJson from "../Json/FilterConfigJson"
|
||||||
import DeleteConfig from "../DeleteConfig"
|
import DeleteConfig from "../DeleteConfig"
|
||||||
|
|
||||||
|
@ -617,6 +617,24 @@ export class DetectMappingsWithImages extends DesugaringStep<TagRenderingConfigJ
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MiscTagRenderingChecks extends DesugaringStep<TagRenderingConfigJson> {
|
||||||
|
constructor() {
|
||||||
|
super("Miscellanious checks on the tagrendering", ["special"], "MiscTagREnderingChecksRew");
|
||||||
|
}
|
||||||
|
|
||||||
|
convert(json: TagRenderingConfigJson, context: string): { result: TagRenderingConfigJson; errors?: string[]; warnings?: string[]; information?: string[] } {
|
||||||
|
const errors = []
|
||||||
|
if(json["special"] !== undefined){
|
||||||
|
errors.push("At "+context+": detected `special` on the top level. Did you mean `{\"render\":{ \"special\": ... }}`")
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
result: json,
|
||||||
|
errors
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
export class ValidateTagRenderings extends Fuse<TagRenderingConfigJson> {
|
export class ValidateTagRenderings extends Fuse<TagRenderingConfigJson> {
|
||||||
constructor(layerConfig?: LayerConfigJson, doesImageExist?: DoesImageExist) {
|
constructor(layerConfig?: LayerConfigJson, doesImageExist?: DoesImageExist) {
|
||||||
super(
|
super(
|
||||||
|
|
|
@ -66,21 +66,24 @@ export default class FilterConfig {
|
||||||
})
|
})
|
||||||
|
|
||||||
for (const field of fields) {
|
for (const field of fields) {
|
||||||
question.OnEveryLanguage((txt, language) => {
|
for (let ln in question.translations) {
|
||||||
|
const txt = question.translations[ln]
|
||||||
|
if(ln.startsWith("_")){
|
||||||
|
continue
|
||||||
|
}
|
||||||
if (txt.indexOf("{" + field.name + "}") < 0) {
|
if (txt.indexOf("{" + field.name + "}") < 0) {
|
||||||
throw (
|
throw (
|
||||||
"Error in filter with fields at " +
|
"Error in filter with fields at " +
|
||||||
context +
|
context +
|
||||||
".question." +
|
".question." +
|
||||||
language +
|
ln +
|
||||||
": The question text should contain every field, but it doesn't contain `{" +
|
": The question text should contain every field, but it doesn't contain `{" +
|
||||||
field +
|
field +
|
||||||
"}`: " +
|
"}`: " +
|
||||||
txt
|
txt
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
return txt
|
}
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (option.default) {
|
if (option.default) {
|
||||||
|
|
|
@ -239,6 +239,9 @@ export default class TagRenderingConfig {
|
||||||
throw `${context}: Detected a freeform key without rendering... Key: ${this.freeform.key} in ${context}`
|
throw `${context}: Detected a freeform key without rendering... Key: ${this.freeform.key} in ${context}`
|
||||||
}
|
}
|
||||||
for (const ln in this.render.translations) {
|
for (const ln in this.render.translations) {
|
||||||
|
if(ln.startsWith("_")){
|
||||||
|
continue
|
||||||
|
}
|
||||||
const txt: string = this.render.translations[ln]
|
const txt: string = this.render.translations[ln]
|
||||||
if (txt === "") {
|
if (txt === "") {
|
||||||
throw context + " Rendering for language " + ln + " is empty"
|
throw context + " Rendering for language " + ln + " is empty"
|
||||||
|
|
|
@ -42,6 +42,9 @@ export default class LanguagePicker extends Toggle {
|
||||||
return new Translation({ "*": nativeText })
|
return new Translation({ "*": nativeText })
|
||||||
}
|
}
|
||||||
for (const key in trans) {
|
for (const key in trans) {
|
||||||
|
if(key.startsWith("_")){
|
||||||
|
continue
|
||||||
|
}
|
||||||
const translationInKey = allTranslations[lang][key]
|
const translationInKey = allTranslations[lang][key]
|
||||||
if (nativeText.toLowerCase() === translationInKey.toLowerCase()) {
|
if (nativeText.toLowerCase() === translationInKey.toLowerCase()) {
|
||||||
translation[key] = nativeText
|
translation[key] = nativeText
|
||||||
|
|
|
@ -16,10 +16,6 @@ export class Translation extends BaseUIElement {
|
||||||
throw `Translation without content (${context})`
|
throw `Translation without content (${context})`
|
||||||
}
|
}
|
||||||
this.context = translations["_context"] ?? context
|
this.context = translations["_context"] ?? context
|
||||||
if (translations["_context"] !== undefined) {
|
|
||||||
translations = { ...translations }
|
|
||||||
delete translations["_context"]
|
|
||||||
}
|
|
||||||
if (typeof translations === "string") {
|
if (typeof translations === "string") {
|
||||||
translations = { "*": translations }
|
translations = { "*": translations }
|
||||||
}
|
}
|
||||||
|
@ -28,7 +24,7 @@ export class Translation extends BaseUIElement {
|
||||||
if (!translations.hasOwnProperty(translationsKey)) {
|
if (!translations.hasOwnProperty(translationsKey)) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if (translationsKey === "_context") {
|
if (translationsKey === "_context" || translationsKey === "_meta") {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
count++
|
count++
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue