Fix(translation-support): use correct weblate link for descriptions on index page

This commit is contained in:
Pieter Vander Vennet 2025-07-12 11:21:57 +02:00
parent c52c2f097a
commit cab3492742
2 changed files with 23 additions and 11 deletions

View file

@ -636,7 +636,10 @@ class LayerOverviewUtils extends Script {
writeFileSync( writeFileSync(
"./src/assets/generated/theme_overview.json", "./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" } { encoding: "utf8" }
) )
} }
@ -1301,7 +1304,7 @@ class LayerOverviewUtils extends Script {
...t, ...t,
hideFromOverview: t.hideFromOverview ?? false, hideFromOverview: t.hideFromOverview ?? false,
shortDescription: shortDescription:
t.shortDescription ?? new Translation(t.description).FirstSentence(), t.shortDescription ?? new Translation(t.description).FirstSentence(true),
mustHaveLanguage: t.mustHaveLanguage?.length > 0, mustHaveLanguage: t.mustHaveLanguage?.length > 0,
} }
}), }),

View file

@ -235,9 +235,6 @@ export class Translation extends BaseUIElement {
): Translation { ): Translation {
const newTranslations = {} const newTranslations = {}
for (const lang in this.translations) { for (const lang in this.translations) {
if (!this.translations.hasOwnProperty(lang)) {
continue
}
newTranslations[lang] = f(this.translations[lang], lang) newTranslations[lang] = f(this.translations[lang], lang)
} }
return new Translation(newTranslations, context ?? this.context) 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 * Build a new translation which only contains the first sentence of every language
* A sentence stops at either a dot (`.`) or a HTML-break ('<br/>'). * A sentence stops at either a dot (`.` or ``) or a HTML-break ('<br/>' or '<br/>').
* The dot or linebreak are _not_ returned. * 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 <br/> This is another sentence"}).FirstSentence().textFor("en") // "This is a sentence" * new Translation({"en": "This is a sentence <br/> This is another sentence"}).FirstSentence().textFor("en") // "This is a sentence"
* new Translation({"en": "This is a sentence <br> This is another sentence"}).FirstSentence().textFor("en") // "This is a sentence" * new Translation({"en": "This is a sentence <br> This is another sentence"}).FirstSentence().textFor("en") // "This is a sentence"
* new Translation({"en": "This is a sentence with a <b>bold</b> word. This is another sentence"}).FirstSentence().textFor("en") // "This is a sentence with a <b>bold</b> word" * new Translation({"en": "This is a sentence with a <b>bold</b> word. This is another sentence"}).FirstSentence().textFor("en") // "This is a sentence with a <b>bold</b> word"
* @constructor * @constructor
*/ */
public FirstSentence(): Translation { public FirstSentence(copyContext: boolean = false): Translation {
const tr = {} const tr = {}
let allSame = true
for (const lng in this.translations) { for (const lng in this.translations) {
if (!this.translations.hasOwnProperty(lng)) { if(lng === "_context"){
continue continue
} }
let txt = this.translations[lng] let txt = this.translations[lng]
txt = txt.replace(/(\.|<br\/>|<br>|。).*/, "") txt = txt.replace(/(\.|<br\/>|<br>|。).*/, "").trim()
txt = Utils.EllipsesAfter(txt, 255) 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)
} }
/** /**