Add overview of all themes if none are defined

This commit is contained in:
Pieter Vander Vennet 2021-01-14 22:25:11 +01:00
parent 7a2b99a566
commit 092c12a449
12 changed files with 94 additions and 53 deletions

View file

@ -11,7 +11,7 @@ export class Translation extends UIElement {
constructor(translations: object, context?: string) {
super(Locale.language)
if(translations === undefined){
if (translations === undefined) {
throw `Translation without content (${context})`
}
let count = 0;
@ -19,11 +19,40 @@ export class Translation extends UIElement {
count++;
}
this.translations = translations;
if(count === 0){
if (count === 0) {
throw `No translations given in the object (${context})`
}
}
get txt(): string {
if (this.translations["*"]) {
return this.translations["*"];
}
const txt = this.translations[Translation.forcedLanguage ?? Locale.language.data];
if (txt !== undefined) {
return txt;
}
const en = this.translations["en"];
if (en !== undefined) {
return en;
}
for (const i in this.translations) {
return this.translations[i]; // Return a random language
}
console.error("Missing language ", Locale.language.data, "for", this.translations)
return "";
}
public SupportedLanguages(): string[] {
const langs = []
for (const translationsKey in this.translations) {
if(translationsKey === "#"){
continue;
}
langs.push(translationsKey)
}
return langs;
}
public Subs(text: any): Translation {
const newTranslations = {};
@ -57,27 +86,6 @@ export class Translation extends UIElement {
}
get txt(): string {
if (this.translations["*"]) {
return this.translations["*"];
}
const txt = this.translations[Translation.forcedLanguage ?? Locale.language.data];
if (txt !== undefined) {
return txt;
}
const en = this.translations["en"];
if (en !== undefined) {
return en;
}
for (const i in this.translations) {
return this.translations[i]; // Return a random language
}
console.error("Missing language ", Locale.language.data, "for", this.translations)
return "";
}
InnerRender(): string {
return this.txt
}