forked from MapComplete/MapComplete
Visualize attribution in the attribution panel
This commit is contained in:
parent
a16745d0d1
commit
12d99e0323
10 changed files with 122 additions and 28 deletions
|
@ -8,6 +8,8 @@ export class Translation extends UIElement {
|
|||
public static forcedLanguage = undefined;
|
||||
|
||||
public readonly translations: object
|
||||
return
|
||||
allIcons;
|
||||
|
||||
constructor(translations: object, context?: string) {
|
||||
super(Locale.language)
|
||||
|
@ -46,7 +48,7 @@ export class Translation extends UIElement {
|
|||
public SupportedLanguages(): string[] {
|
||||
const langs = []
|
||||
for (const translationsKey in this.translations) {
|
||||
if(translationsKey === "#"){
|
||||
if (translationsKey === "#") {
|
||||
continue;
|
||||
}
|
||||
langs.push(translationsKey)
|
||||
|
@ -102,7 +104,6 @@ export class Translation extends UIElement {
|
|||
return new Translation(this.translations)
|
||||
}
|
||||
|
||||
|
||||
FirstSentence() {
|
||||
|
||||
const tr = {};
|
||||
|
@ -115,4 +116,23 @@ export class Translation extends UIElement {
|
|||
|
||||
return new Translation(tr);
|
||||
}
|
||||
|
||||
public ExtractImages(isIcon = false): string[] {
|
||||
const allIcons: string[] = []
|
||||
for (const key in this.translations) {
|
||||
const render = this.translations[key]
|
||||
|
||||
if (isIcon) {
|
||||
const icons = render.split(";").filter(part => part.match(/(\.svg|\.png|\.jpg)$/) != null)
|
||||
allIcons.push(...icons)
|
||||
} else if(!Utils.runningFromConsole){
|
||||
// This might be a tagrendering containing some img as html
|
||||
const htmlElement = document.createElement("div")
|
||||
htmlElement.innerHTML = render
|
||||
const images = Array.from(htmlElement.getElementsByTagName("img")).map(img => img.src)
|
||||
allIcons.push(...images)
|
||||
}
|
||||
}
|
||||
return allIcons.filter(icon => icon != undefined)
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue