Accessibility: add (translatable) aria labels, update to translation system, see #1181

This commit is contained in:
Pieter Vander Vennet 2023-12-12 19:18:50 +01:00
parent 825fd03adb
commit 8a7d8a43ce
12 changed files with 130 additions and 72 deletions

View file

@ -2,6 +2,7 @@ import Locale from "./Locale"
import { Utils } from "../../Utils"
import BaseUIElement from "../BaseUIElement"
import LinkToWeblate from "../Base/LinkToWeblate"
import { Store } from "../../Logic/UIEventSource"
export class Translation extends BaseUIElement {
public static forcedLanguage = undefined
@ -9,6 +10,9 @@ export class Translation extends BaseUIElement {
public readonly translations: Record<string, string>
public readonly context?: string
private _current: Store<string>
private onDestroy: () => void
constructor(translations: string | Record<string, string>, context?: string) {
super()
if (translations === undefined) {
@ -66,6 +70,18 @@ export class Translation extends BaseUIElement {
return this.textFor(Translation.forcedLanguage ?? Locale.language.data)
}
get current(): Store<string> {
if (!this._current) {
this._current = Locale.language.map(
(l) => this.textFor(l),
[],
(f) => {
this.onDestroy = f
}
)
}
return this._current
}
static ExtractAllTranslationsFrom(
object: any,
context = ""
@ -108,6 +124,7 @@ export class Translation extends BaseUIElement {
Destroy() {
super.Destroy()
this.onDestroy()
this.isDestroyed = true
}