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
|
||||
* const errors = []
|
||||
* 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
|
||||
* const errors = []
|
||||
|
@ -593,7 +593,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
|||
...Array.from(Object.keys(input))
|
||||
.filter((k) => k !== "special" && k !== "before" && k !== "after")
|
||||
.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,
|
||||
(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]
|
||||
}?\n\tAll known arguments are ${argNamesList.join(", ")}`
|
||||
})
|
||||
|
@ -623,7 +623,7 @@ export class RewriteSpecial extends DesugaringStep<TagRenderingConfigJson> {
|
|||
}
|
||||
const param = special[arg.name]
|
||||
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
|
||||
}
|
||||
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 { LayerConfigJson } from "../Json/LayerConfigJson"
|
||||
import {DesugaringStep, Each, Fuse, On} from "./Conversion"
|
||||
import {LayerConfigJson} from "../Json/LayerConfigJson"
|
||||
import LayerConfig from "../LayerConfig"
|
||||
import { Utils } from "../../../Utils"
|
||||
import {Utils} from "../../../Utils"
|
||||
import Constants from "../../Constants"
|
||||
import { Translation } from "../../../UI/i18n/Translation"
|
||||
import { LayoutConfigJson } from "../Json/LayoutConfigJson"
|
||||
import {Translation} from "../../../UI/i18n/Translation"
|
||||
import {LayoutConfigJson} from "../Json/LayoutConfigJson"
|
||||
import LayoutConfig from "../LayoutConfig"
|
||||
import { TagRenderingConfigJson } from "../Json/TagRenderingConfigJson"
|
||||
import { TagUtils } from "../../../Logic/Tags/TagUtils"
|
||||
import { ExtractImages } from "./FixImages"
|
||||
import {TagRenderingConfigJson} from "../Json/TagRenderingConfigJson"
|
||||
import {TagUtils} from "../../../Logic/Tags/TagUtils"
|
||||
import {ExtractImages} from "./FixImages"
|
||||
import ScriptUtils from "../../../scripts/ScriptUtils"
|
||||
import { And } from "../../../Logic/Tags/And"
|
||||
import {And} from "../../../Logic/Tags/And"
|
||||
import Translations from "../../../UI/i18n/Translations"
|
||||
import Svg from "../../../Svg"
|
||||
import { QuestionableTagRenderingConfigJson } from "../Json/QuestionableTagRenderingConfigJson"
|
||||
import {QuestionableTagRenderingConfigJson} from "../Json/QuestionableTagRenderingConfigJson"
|
||||
import FilterConfigJson from "../Json/FilterConfigJson"
|
||||
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> {
|
||||
constructor(layerConfig?: LayerConfigJson, doesImageExist?: DoesImageExist) {
|
||||
super(
|
||||
|
|
|
@ -66,21 +66,24 @@ export default class FilterConfig {
|
|||
})
|
||||
|
||||
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) {
|
||||
throw (
|
||||
"Error in filter with fields at " +
|
||||
context +
|
||||
".question." +
|
||||
language +
|
||||
ln +
|
||||
": The question text should contain every field, but it doesn't contain `{" +
|
||||
field +
|
||||
"}`: " +
|
||||
txt
|
||||
)
|
||||
}
|
||||
return txt
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
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}`
|
||||
}
|
||||
for (const ln in this.render.translations) {
|
||||
if(ln.startsWith("_")){
|
||||
continue
|
||||
}
|
||||
const txt: string = this.render.translations[ln]
|
||||
if (txt === "") {
|
||||
throw context + " Rendering for language " + ln + " is empty"
|
||||
|
|
|
@ -42,6 +42,9 @@ export default class LanguagePicker extends Toggle {
|
|||
return new Translation({ "*": nativeText })
|
||||
}
|
||||
for (const key in trans) {
|
||||
if(key.startsWith("_")){
|
||||
continue
|
||||
}
|
||||
const translationInKey = allTranslations[lang][key]
|
||||
if (nativeText.toLowerCase() === translationInKey.toLowerCase()) {
|
||||
translation[key] = nativeText
|
||||
|
|
|
@ -16,10 +16,6 @@ export class Translation extends BaseUIElement {
|
|||
throw `Translation without content (${context})`
|
||||
}
|
||||
this.context = translations["_context"] ?? context
|
||||
if (translations["_context"] !== undefined) {
|
||||
translations = { ...translations }
|
||||
delete translations["_context"]
|
||||
}
|
||||
if (typeof translations === "string") {
|
||||
translations = { "*": translations }
|
||||
}
|
||||
|
@ -28,7 +24,7 @@ export class Translation extends BaseUIElement {
|
|||
if (!translations.hasOwnProperty(translationsKey)) {
|
||||
continue
|
||||
}
|
||||
if (translationsKey === "_context") {
|
||||
if (translationsKey === "_context" || translationsKey === "_meta") {
|
||||
continue
|
||||
}
|
||||
count++
|
||||
|
|
Loading…
Reference in a new issue