mapcomplete/UI/i18n/Translation.ts

31 lines
750 B
TypeScript
Raw Normal View History

2020-07-20 10:39:43 +00:00
import { UIElement } from "../UIElement"
import Locale from "./Locale"
2020-07-20 22:07:04 +00:00
import {FixedUiElement} from "../Base/FixedUiElement";
2020-07-20 10:39:43 +00:00
2020-07-20 22:07:04 +00:00
export default class Translation extends UIElement {
2020-07-20 10:39:43 +00:00
public readonly translations: object
2020-07-20 22:07:04 +00:00
2020-07-20 10:39:43 +00:00
constructor(translations: object) {
super(Locale.language)
this.translations = translations
}
2020-07-20 22:07:04 +00:00
public R(): string {
return new Translation(this.translations).Render();
}
InnerRender(): string {
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);
return en;
}
2020-07-20 10:39:43 +00:00
}