Add _context key to themes for translations, all strings can now be translated

This commit is contained in:
Pieter Vander Vennet 2022-04-06 17:28:51 +02:00
parent db2b14cd95
commit a9aff5e16e
7 changed files with 105 additions and 21 deletions

View file

@ -15,11 +15,15 @@ export class Translation extends BaseUIElement {
constructor(translations: object, context?: string) {
super()
this.context = context;
if (translations === undefined) {
console.error("Translation without content at "+context)
throw `Translation without content (${context})`
}
this.context = translations["_context"] ?? context;
if(translations["_context"] !== undefined){
translations = {...translations}
delete translations["_context"]
}
if (typeof translations === "string") {
translations = {"*": translations};
}
@ -28,6 +32,9 @@ export class Translation extends BaseUIElement {
if (!translations.hasOwnProperty(translationsKey)) {
continue
}
if(translationsKey === "_context"){
continue
}
count++;
if (typeof (translations[translationsKey]) != "string") {
console.error("Non-string object in translation: ", translations[translationsKey])