forked from MapComplete/MapComplete
Full code cleanup
This commit is contained in:
parent
8e6ee8c87f
commit
bd21212eba
246 changed files with 19418 additions and 11729 deletions
|
@ -34,6 +34,38 @@ export class Translation extends BaseUIElement {
|
|||
return this.textFor(Translation.forcedLanguage ?? Locale.language.data)
|
||||
}
|
||||
|
||||
static ExtractAllTranslationsFrom(object: any, context = ""): { context: string, tr: Translation }[] {
|
||||
const allTranslations: { context: string, tr: Translation }[] = []
|
||||
for (const key in object) {
|
||||
const v = object[key]
|
||||
if (v === undefined || v === null) {
|
||||
continue
|
||||
}
|
||||
if (v instanceof Translation) {
|
||||
allTranslations.push({context: context + "." + key, tr: v})
|
||||
continue
|
||||
}
|
||||
if (typeof v === "object") {
|
||||
allTranslations.push(...Translation.ExtractAllTranslationsFrom(v, context + "." + key))
|
||||
|
||||
}
|
||||
}
|
||||
return allTranslations
|
||||
}
|
||||
|
||||
static fromMap(transl: Map<string, string>) {
|
||||
const translations = {}
|
||||
let hasTranslation = false;
|
||||
transl?.forEach((value, key) => {
|
||||
translations[key] = value
|
||||
hasTranslation = true
|
||||
})
|
||||
if (!hasTranslation) {
|
||||
return undefined
|
||||
}
|
||||
return new Translation(translations);
|
||||
}
|
||||
|
||||
public textFor(language: string): string {
|
||||
if (this.translations["*"]) {
|
||||
return this.translations["*"];
|
||||
|
@ -195,36 +227,4 @@ export class Translation extends BaseUIElement {
|
|||
}
|
||||
return allIcons.filter(icon => icon != undefined)
|
||||
}
|
||||
|
||||
static ExtractAllTranslationsFrom(object: any, context = ""): { context: string, tr: Translation }[] {
|
||||
const allTranslations: { context: string, tr: Translation }[] = []
|
||||
for (const key in object) {
|
||||
const v = object[key]
|
||||
if (v === undefined || v === null) {
|
||||
continue
|
||||
}
|
||||
if (v instanceof Translation) {
|
||||
allTranslations.push({context: context +"." + key, tr: v})
|
||||
continue
|
||||
}
|
||||
if (typeof v === "object") {
|
||||
allTranslations.push(...Translation.ExtractAllTranslationsFrom(v, context + "." + key))
|
||||
continue
|
||||
}
|
||||
}
|
||||
return allTranslations
|
||||
}
|
||||
|
||||
static fromMap(transl: Map<string, string>) {
|
||||
const translations = {}
|
||||
let hasTranslation = false;
|
||||
transl?.forEach((value, key) => {
|
||||
translations[key] = value
|
||||
hasTranslation = true
|
||||
})
|
||||
if(!hasTranslation){
|
||||
return undefined
|
||||
}
|
||||
return new Translation(translations);
|
||||
}
|
||||
}
|
|
@ -25,8 +25,8 @@ export default class Translations {
|
|||
if (t === undefined || t === null) {
|
||||
return undefined;
|
||||
}
|
||||
if(typeof t === "number"){
|
||||
t = ""+t
|
||||
if (typeof t === "number") {
|
||||
t = "" + t
|
||||
}
|
||||
if (typeof t === "string") {
|
||||
return new Translation({"*": t}, context);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue