2020-07-20 12:39:43 +02:00
|
|
|
import { UIElement } from "../UIElement"
|
|
|
|
import Locale from "./Locale"
|
2020-07-21 00:07:04 +02:00
|
|
|
import {FixedUiElement} from "../Base/FixedUiElement";
|
2020-07-20 12:39:43 +02:00
|
|
|
|
|
|
|
|
2020-07-21 00:07:04 +02:00
|
|
|
export default class Translation extends UIElement {
|
2020-07-20 23:43:42 +02:00
|
|
|
get txt(): string {
|
2020-07-21 01:13:51 +02:00
|
|
|
const txt = this.translations[Locale.language.data];
|
|
|
|
if (txt !== undefined) {
|
|
|
|
return txt;
|
|
|
|
}
|
|
|
|
const en = this.translations["en"];
|
|
|
|
console.warn("No translation for language ", Locale.language.data, "for", en);
|
2020-07-21 15:18:11 +02:00
|
|
|
if (en !== undefined) {
|
|
|
|
return en;
|
|
|
|
}
|
|
|
|
for (const i in this.translations) {
|
|
|
|
return this.translations[i]; // Return a random language
|
|
|
|
}
|
|
|
|
return "Missing translation"
|
2020-07-20 12:39:43 +02:00
|
|
|
}
|
|
|
|
|
2020-07-21 01:13:51 +02:00
|
|
|
InnerRender(): string {
|
2020-07-20 23:43:42 +02:00
|
|
|
return this.txt
|
|
|
|
}
|
2020-07-20 12:39:43 +02:00
|
|
|
|
|
|
|
public readonly translations: object
|
2020-07-21 00:07:04 +02:00
|
|
|
|
2020-07-20 12:39:43 +02:00
|
|
|
constructor(translations: object) {
|
|
|
|
super(Locale.language)
|
|
|
|
this.translations = translations
|
|
|
|
}
|
2020-07-21 00:07:04 +02:00
|
|
|
|
2020-07-21 01:13:51 +02:00
|
|
|
|
2020-07-21 00:07:04 +02:00
|
|
|
public R(): string {
|
|
|
|
return new Translation(this.translations).Render();
|
|
|
|
}
|
|
|
|
|
2020-07-20 12:39:43 +02:00
|
|
|
}
|