From 0f528ac7e031b4cab1a7caa1a032e6453897c2d6 Mon Sep 17 00:00:00 2001 From: _Bastler <_Bastler@bstly.de> Date: Wed, 17 Nov 2021 20:40:09 +0100 Subject: [PATCH] fix profile names --- src/app/services/i18n.service.ts | 16 ++++++++++------ src/app/ui/confirm/confirm.component.ts | 2 +- src/app/ui/profilefields/profilefield.blob.html | 2 +- .../ui/profilefields/profilefield.dialog.html | 2 +- .../profilefields/profilefields.component.html | 2 +- .../ui/profilefields/profilefields.component.ts | 3 ++- src/app/utils/i18n.pipe.ts | 13 +++++++++++++ 7 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/app/services/i18n.service.ts b/src/app/services/i18n.service.ts index 3e844b7..38cca7a 100644 --- a/src/app/services/i18n.service.ts +++ b/src/app/services/i18n.service.ts @@ -65,30 +65,34 @@ export class I18nService { } get(key, args: string[]): string { - return this.getInternal(key, args, this.i18n, ""); + return this.getInternal(key, args, this.i18n, "", true); } - getInternal(key, args: string[], from, path): string { + getEmpty(key, args: string[]): string { + return this.getInternal(key, args, this.i18n, "", false); + } + + getInternal(key, args: string[], from, path, empty : boolean): string { key += ''; if (!from) { - return this.empty(key, args, path); + return empty ? this.empty(key, args, path) : key; } else if (from[ key ]) { if (typeof from[ key ] === 'object') { if (from[ key ][ "." ]) { return this.insertArguments(from[ key ][ "." ], args); } - return this.empty(key, args, path); + return empty ? this.empty(key, args, path) : key; } return this.insertArguments(from[ key ], args); } else { let keys = key.split("."); if (from[ keys[ 0 ] ]) { key = keys.slice(1, keys.length).join("."); - return this.getInternal(key, args, from[ keys[ 0 ] ], path + keys[ 0 ] + ".") + return this.getInternal(key, args, from[ keys[ 0 ] ], path + keys[ 0 ] + ".", empty) } } - return this.empty(key, args, path); + return empty ? this.empty(key, args, path) : key; } empty(key, args: string[], path: string): string { diff --git a/src/app/ui/confirm/confirm.component.ts b/src/app/ui/confirm/confirm.component.ts index 9bcb099..76443ef 100644 --- a/src/app/ui/confirm/confirm.component.ts +++ b/src/app/ui/confirm/confirm.component.ts @@ -14,7 +14,7 @@ export class ConfirmDialog { constructor(private i18nService: I18nService, public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any) { - this.text = i18nService.get(data.label, data.args); + this.text = data.empty ? i18nService.getEmpty(data.label, data.args) : i18nService.get(data.label, data.args); } } diff --git a/src/app/ui/profilefields/profilefield.blob.html b/src/app/ui/profilefields/profilefield.blob.html index 8e22cdd..4c7531d 100644 --- a/src/app/ui/profilefields/profilefield.blob.html +++ b/src/app/ui/profilefields/profilefield.blob.html @@ -1,4 +1,4 @@ -

{{'profileField.name.' + profileField.name | i18n}}

+

{{'profileField.name.' + profileField.name | i18nEmpty}}

     {{profileField.blob}}
diff --git a/src/app/ui/profilefields/profilefield.dialog.html b/src/app/ui/profilefields/profilefield.dialog.html
index 4608af3..27d8614 100644
--- a/src/app/ui/profilefields/profilefield.dialog.html
+++ b/src/app/ui/profilefields/profilefield.dialog.html
@@ -1,4 +1,4 @@
-

{{'profileField.name.' + profileField.name | i18n}}

+

{{'profileField.name.' + profileField.name | i18nEmpty}}

diff --git a/src/app/ui/profilefields/profilefields.component.html b/src/app/ui/profilefields/profilefields.component.html index da71e96..affc4b0 100644 --- a/src/app/ui/profilefields/profilefields.component.html +++ b/src/app/ui/profilefields/profilefields.component.html @@ -2,7 +2,7 @@ {{'profileField.name' | i18n}} - {{'profileField.name.' + profileField.name | i18n}} + {{'profileField.name.' + profileField.name | i18nEmpty}} diff --git a/src/app/ui/profilefields/profilefields.component.ts b/src/app/ui/profilefields/profilefields.component.ts index f94003e..29ed4ee 100644 --- a/src/app/ui/profilefields/profilefields.component.ts +++ b/src/app/ui/profilefields/profilefields.component.ts @@ -61,7 +61,7 @@ export class ProfileFieldsComponent implements OnInit { this.profileFields = data.sort((a, b) => { const isAsc = sort.direction === 'asc'; switch(sort.active) { - case 'name': return this.compare(this.i18n.get('profileField.name.' + a.name, []), this.i18n.get('profileField.name.' + b.name, []), isAsc); + case 'name': return this.compare(this.i18n.getEmpty('profileField.name.' + a.name, []), this.i18n.getEmpty('profileField.name.' + b.name, []), isAsc); case 'value': return this.compare(a.value, b.value, isAsc); case 'index': return this.compare(a.index, b.index, isAsc); case 'visibility': return this.compare(this.i18n.get('visibility.' + a.visibility, []), this.i18n.get('visibility.' + b.visibility, []), isAsc); @@ -105,6 +105,7 @@ export class ProfileFieldsComponent implements OnInit { const dialogRef = this.dialog.open(ConfirmDialog, { data: { 'label': 'profileField.confirmDelete', + 'empty' : true, 'args': ['profileField.name.' + profileField.name] } }) diff --git a/src/app/utils/i18n.pipe.ts b/src/app/utils/i18n.pipe.ts index 2651e83..516a63d 100644 --- a/src/app/utils/i18n.pipe.ts +++ b/src/app/utils/i18n.pipe.ts @@ -15,4 +15,17 @@ export class I18nPipe implements PipeTransform { transform(value: String, ...args: any[]): String { return this.i18n.get(value, args); } +} + +@Pipe({ + name: 'i18nEmpty' +}) +export class I18nEmptyPipe implements PipeTransform { + + constructor(private i18n: I18nService) { + } + + transform(value: String, ...args: any[]): String { + return this.i18n.getEmpty(value, args); + } } \ No newline at end of file