forked from MapComplete/MapComplete
Add _context key to themes for translations, all strings can now be translated
This commit is contained in:
parent
db2b14cd95
commit
a9aff5e16e
7 changed files with 105 additions and 21 deletions
|
@ -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])
|
||||
|
|
|
@ -107,7 +107,7 @@ export default class Translations {
|
|||
return false
|
||||
}
|
||||
// is a weird key found?
|
||||
if(Object.keys(transl).some(key => !this.knownLanguages.has(key))){
|
||||
if(Object.keys(transl).some(key => key !== '_context' && !this.knownLanguages.has(key))){
|
||||
return false
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue