diff --git a/Models/Constants.ts b/Models/Constants.ts index bf95f3f272..ae26b89d58 100644 --- a/Models/Constants.ts +++ b/Models/Constants.ts @@ -2,7 +2,7 @@ import {Utils} from "../Utils"; export default class Constants { - public static vNumber = "0.16.4"; + public static vNumber = "0.17.0-alpha"; public static ImgurApiKey = '7070e7167f0a25a' public static readonly mapillary_client_token_v4 = "MLY|4441509239301885|b40ad2d3ea105435bd40c7e76993ae85" diff --git a/Models/ThemeConfig/Conversion/Conversion.ts b/Models/ThemeConfig/Conversion/Conversion.ts index bce74f5ebd..13f352eea1 100644 --- a/Models/ThemeConfig/Conversion/Conversion.ts +++ b/Models/ThemeConfig/Conversion/Conversion.ts @@ -113,7 +113,9 @@ export class OnEveryConcat extends DesugaringStep { } const r = step.convertAll((values), context + "." + key) const vals: X[][] = r.result + json[key] = [].concat(...vals) + return { ...r, result: json, diff --git a/Models/ThemeConfig/Conversion/PrepareLayer.ts b/Models/ThemeConfig/Conversion/PrepareLayer.ts index 82ced05b5a..6b02e70e9f 100644 --- a/Models/ThemeConfig/Conversion/PrepareLayer.ts +++ b/Models/ThemeConfig/Conversion/PrepareLayer.ts @@ -279,25 +279,27 @@ class ExpandRewrite extends Conversion, T[]> { * Every 'keyToRewrite' will be replaced with 'target' recursively. This substitution will happen in place in the object 'tr' */ public static RewriteParts(keyToRewrite: string, target: string | any, tr: T): T { - const isTranslation = typeof target !== "string" - function replaceRecursive(transl: string | any) { + + if(transl === keyToRewrite){ + return target + } + if (typeof transl === "string") { // This is a simple string - we do a simple replace return transl.replace(keyToRewrite, target) } - if (transl.map !== undefined) { + if (Array.isArray(transl)) { // This is a list of items return transl.map(o => replaceRecursive(o)) } - if (Translations.isProbablyATranslation(transl) && isTranslation) { - return Translations.T(transl).Fuse(new Translation(target), keyToRewrite).translations - } - - transl = {...transl} - for (const key in transl) { - transl[key] = replaceRecursive(transl[key]) + if(typeof transl === "object"){ + transl = {...transl} + for (const key in transl) { + transl[key] = replaceRecursive(transl[key]) + } + return transl } return transl } @@ -318,10 +320,19 @@ class ExpandRewrite extends Conversion, T[]> { } const rewrite = >json; - let toRewrite: T = rewrite.renderings - const keysToRewrite = rewrite.rewrite + const keysToRewrite = rewrite.rewrite const ts : T[] = [] + for (let i = 0; i < keysToRewrite.sourceString.length; i++){ + const guard = keysToRewrite.sourceString[i]; + for (let j = i + 1; j < keysToRewrite.sourceString.length; j++) { + const toRewrite = keysToRewrite.sourceString[j] + if(toRewrite.indexOf(guard) >= 0){ + throw `${context} Error in rewrite: sourcestring[${i}] is a substring of sourcestring[${j}]: ${guard} will be substituted away before ${toRewrite} is reached.` + } + } + } + for (let i = 0; i < keysToRewrite.into[0].length; i++){ let t = Utils.Clone(rewrite.renderings) for (let i1 = 0; i1 < keysToRewrite.sourceString.length; i1++){ @@ -338,6 +349,22 @@ class ExpandRewrite extends Conversion, T[]> { } + +class ExpandRewriteWithFlatten extends Conversion, T[]> { + + private _rewrite = new ExpandRewrite() + + constructor() { + super("Applies a rewrite, the result is flattened if it is an array", [], "ExpandRewriteWithFlatten"); + } + + convert(json: RewritableConfigJson | T, context: string): { result: T[]; errors?: string[]; warnings?: string[]; information?: string[] } { + return undefined; + } + + +} + export class PrepareLayer extends Fuse { constructor(state: DesugaringContext) { super( diff --git a/Models/ThemeConfig/Json/LayerConfigJson.ts b/Models/ThemeConfig/Json/LayerConfigJson.ts index 805efd0acb..9bc71e38fc 100644 --- a/Models/ThemeConfig/Json/LayerConfigJson.ts +++ b/Models/ThemeConfig/Json/LayerConfigJson.ts @@ -179,7 +179,7 @@ export interface LayerConfigJson { /** * Visualisation of the items on the map */ - mapRendering: null | (PointRenderingConfigJson | LineRenderingConfigJson | RewritableConfigJson)[] + mapRendering: null | (PointRenderingConfigJson | LineRenderingConfigJson | RewritableConfigJson)[] /** * If set, this layer will pass all the features it receives onto the next layer. diff --git a/UI/i18n/Translation.ts b/UI/i18n/Translation.ts index 30a0f74cb2..1c11661fa4 100644 --- a/UI/i18n/Translation.ts +++ b/UI/i18n/Translation.ts @@ -11,6 +11,7 @@ export class Translation extends BaseUIElement { constructor(translations: object, context?: string) { super() if (translations === undefined) { + console.error("Translation without content at "+context) throw `Translation without content (${context})` } if (typeof translations === "string") { @@ -29,7 +30,8 @@ export class Translation extends BaseUIElement { } this.translations = translations; if (count === 0) { - throw `No translations given in the object (${context})` + console.error("Constructing a translation, but the object containing translations is empty "+context) + throw `Constructing a translation, but the object containing translations is empty (${context})` } } diff --git a/UI/i18n/Translations.ts b/UI/i18n/Translations.ts index 72ed3a4e5f..dde9601d3e 100644 --- a/UI/i18n/Translations.ts +++ b/UI/i18n/Translations.ts @@ -94,7 +94,15 @@ export default class Translations { if(typeof transl !== "object"){ return false; } + if(Object.keys(transl).length == 0){ + // No translations found; not a translation + return false + } // is a weird key found? - return !Object.keys(transl).some(key => !this.knownLanguages.has(key)) + if(Object.keys(transl).some(key => !this.knownLanguages.has(key))){ + return false + } + + return true; } } diff --git a/assets/layers/bench/bench.json b/assets/layers/bench/bench.json index c96a91085e..c8f3f481ab 100644 --- a/assets/layers/bench/bench.json +++ b/assets/layers/bench/bench.json @@ -157,7 +157,6 @@ "hu": "Anyag: {material}", "it": "Materiale: {material}", "ru": "Материал: {material}", - "zh_Hanå¨s": "材质: {material}", "zh_Hant": "材質:{material}", "nb_NO": "Materiale: {material}", "fi": "Materiaali: {material}", diff --git a/langs/themes/en.json b/langs/themes/en.json index 5997286d9a..deae423e00 100644 --- a/langs/themes/en.json +++ b/langs/themes/en.json @@ -879,6 +879,17 @@ "question": "What kind of building is this?" } } + }, + "6": { + "tagRenderings": { + "Import-button": { + "mappings": { + "0": { + "then": "Did not yet calculate the metatags... Reopen this popup" + } + } + } + } } } }, diff --git a/test/LegacyThemeLoader.spec.ts b/test/LegacyThemeLoader.spec.ts index 5de6c625c1..9053e80141 100644 --- a/test/LegacyThemeLoader.spec.ts +++ b/test/LegacyThemeLoader.spec.ts @@ -581,7 +581,7 @@ export default class LegacyThemeLoaderSpec extends T { {"if": "parking:condition:left=disc", "then": "#219991"}] }, - "offset": "-6" + "offset": -6 }, { "color": { "render": "#888", @@ -592,7 +592,7 @@ export default class LegacyThemeLoaderSpec extends T { {"if": "parking:condition:right=disc", "then": "#219991"}] }, - "offset": "6" + "offset": 6 }], "titleIcons": [{"render": "defaults", "id": "defaults"}] } @@ -601,7 +601,56 @@ export default class LegacyThemeLoaderSpec extends T { Assert.equal(JSON.stringify(result), JSON.stringify(expected)) } + ], + ["Advanced rewriting of the mapRendering",() => { + const source = {"mapRendering": [ + { + "rewrite": { + "sourceString": ["left|right", "lr_offset"], + "into": [ + ["left", "right"], + [-6, 6] + ] + }, + "renderings": [ + { + "color": { + "render": "#888", + "mappings": [ + { + "if": "parking:condition:left|right=free", + "then": "#299921" + }, + { + "if": "parking:condition:left|right=ticket", + "then": "#219991" + } + ] + }, + "width": { + "render": 6, + "mappings": [ + { + "if": { + "or": [ + "parking:lane:left|right=no", + "parking:lane:left|right=separate" + ] + }, + "then": 0 + } + ] + }, + "offset": "lr_offset", + "lineCap": "butt" + } + ] + } ] + }} + + + ] ] ); }