Refactored out 'layout.ts'

This commit is contained in:
Pieter Vander Vennet 2020-11-11 16:23:49 +01:00
parent 36f5e896df
commit 73f32e0ecf
30 changed files with 465 additions and 400 deletions

View file

@ -7,6 +7,24 @@ export class Translation extends UIElement {
private static forcedLanguage = undefined;
public readonly translations: object
constructor(translations: object, context?: string) {
super(Locale.language)
if(translations === undefined){
throw `Translation without content (${context})`
}
let count = 0;
for (const translationsKey in translations) {
count++;
}
this.translations = translations;
if(count === 0){
throw `No translations given in the object (${context})`
}
}
public Subs(text: any): Translation {
const newTranslations = {};
for (const lang in this.translations) {
@ -56,7 +74,7 @@ export class Translation extends UIElement {
return this.translations[i]; // Return a random language
}
console.error("Missing language ", Locale.language.data, "for", this.translations)
return undefined;
return "";
}
@ -64,17 +82,6 @@ export class Translation extends UIElement {
return this.txt
}
public readonly translations: object
constructor(translations: object) {
super(Locale.language)
let count = 0;
for (const translationsKey in translations) {
count++;
}
this.translations = translations
}
public replace(a: string, b: string) {
if (a.startsWith("{") && a.endsWith("}")) {
a = a.substr(1, a.length - 2);

View file

@ -10,17 +10,6 @@ export default class Translations {
}
static t = AllTranslationAssets.t;
private static isTranslation(tr: any): boolean {
for (const key in tr) {
if (typeof tr[key] !== "string") {
return false;
}
}
return true;
}
public static W(s: string | UIElement): UIElement {
if (typeof (s) === "string") {
return new FixedUiElement(s);