diff --git a/scripts/generateLayerOverview.ts b/scripts/generateLayerOverview.ts index fb7012746..d8543e465 100644 --- a/scripts/generateLayerOverview.ts +++ b/scripts/generateLayerOverview.ts @@ -636,7 +636,10 @@ class LayerOverviewUtils extends Script { writeFileSync( "./src/assets/generated/theme_overview.json", - JSON.stringify({ layers: layerKeywords, themes: sorted }, null, " "), + JSON.stringify({ + "#":"Generated by generateLayerOverview", + "#version": new Date().toISOString(), + layers: layerKeywords, themes: sorted }, null, " "), { encoding: "utf8" } ) } @@ -1301,7 +1304,7 @@ class LayerOverviewUtils extends Script { ...t, hideFromOverview: t.hideFromOverview ?? false, shortDescription: - t.shortDescription ?? new Translation(t.description).FirstSentence(), + t.shortDescription ?? new Translation(t.description).FirstSentence(true), mustHaveLanguage: t.mustHaveLanguage?.length > 0, } }), diff --git a/src/UI/i18n/Translation.ts b/src/UI/i18n/Translation.ts index 6b1d30f67..694fabca8 100644 --- a/src/UI/i18n/Translation.ts +++ b/src/UI/i18n/Translation.ts @@ -235,9 +235,6 @@ export class Translation extends BaseUIElement { ): Translation { const newTranslations = {} for (const lang in this.translations) { - if (!this.translations.hasOwnProperty(lang)) { - continue - } newTranslations[lang] = f(this.translations[lang], lang) } return new Translation(newTranslations, context ?? this.context) @@ -265,28 +262,40 @@ export class Translation extends BaseUIElement { /** * Build a new translation which only contains the first sentence of every language - * A sentence stops at either a dot (`.`) or a HTML-break ('
'). + * A sentence stops at either a dot (`.` or `。`) or a HTML-break ('
' or '
'). * The dot or linebreak are _not_ returned. * + * @param copyContext if set, the context of 'this' will be added to the new translation. If not, _context will be removed alltogether + * @return The object itself (this) if all strings are the same + * * new Translation({"en": "This is a sentence. This is another sentence"}).FirstSentence().textFor("en") // "This is a sentence" * new Translation({"en": "This is a sentence
This is another sentence"}).FirstSentence().textFor("en") // "This is a sentence" * new Translation({"en": "This is a sentence
This is another sentence"}).FirstSentence().textFor("en") // "This is a sentence" * new Translation({"en": "This is a sentence with a bold word. This is another sentence"}).FirstSentence().textFor("en") // "This is a sentence with a bold word" * @constructor */ - public FirstSentence(): Translation { + public FirstSentence(copyContext: boolean = false): Translation { const tr = {} + let allSame = true for (const lng in this.translations) { - if (!this.translations.hasOwnProperty(lng)) { + if(lng === "_context"){ continue } let txt = this.translations[lng] - txt = txt.replace(/(\.||
|。).*/, "") + txt = txt.replace(/(\.||
|。).*/, "").trim() txt = Utils.EllipsesAfter(txt, 255) - tr[lng] = txt.trim() + allSame = allSame && txt == this.translations[lng] + tr[lng] = txt + } + if(allSame){ + return this } - return new Translation(tr) + if(copyContext && this.context){ + tr["_context"] = this.context + } + + return new Translation(tr, copyContext ? this.context : null) } /**