forked from MapComplete/MapComplete
Fix(translation-support): use correct weblate link for descriptions on index page
This commit is contained in:
parent
c52c2f097a
commit
cab3492742
2 changed files with 23 additions and 11 deletions
|
@ -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,
|
||||
}
|
||||
}),
|
||||
|
|
|
@ -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 ('<br/>').
|
||||
* A sentence stops at either a dot (`.` or `。`) or a HTML-break ('<br/>' or '<br/>').
|
||||
* 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 <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"
|
||||
* @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(/(\.|<br\/>|<br>|。).*/, "")
|
||||
txt = txt.replace(/(\.|<br\/>|<br>|。).*/, "").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)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue