fix profile names

This commit is contained in:
_Bastler 2021-11-17 20:40:09 +01:00
parent d2eb8fd261
commit 0f528ac7e0
7 changed files with 29 additions and 11 deletions

View File

@ -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 {

View File

@ -14,7 +14,7 @@ export class ConfirmDialog {
constructor(private i18nService: I18nService,
public dialogRef: MatDialogRef<ConfirmDialog>,
@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);
}
}

View File

@ -1,4 +1,4 @@
<h1 mat-dialog-title>{{'profileField.name.' + profileField.name | i18n}}</h1>
<h1 mat-dialog-title>{{'profileField.name.' + profileField.name | i18nEmpty}}</h1>
<mat-dialog-content>
<pre>
{{profileField.blob}}

View File

@ -1,4 +1,4 @@
<h1 mat-dialog-title>{{'profileField.name.' + profileField.name | i18n}}</h1>
<h1 mat-dialog-title>{{'profileField.name.' + profileField.name | i18nEmpty}}</h1>
<mat-dialog-content>
<form [formGroup]="form">
<mat-form-field>

View File

@ -2,7 +2,7 @@
<ng-container matColumnDef="name">
<th mat-header-cell *matHeaderCellDef mat-sort-header="name"> {{'profileField.name' | i18n}} </th>
<td mat-cell *matCellDef="let profileField"> {{'profileField.name.' + profileField.name | i18n}} </td>
<td mat-cell *matCellDef="let profileField"> {{'profileField.name.' + profileField.name | i18nEmpty}} </td>
</ng-container>
<ng-container matColumnDef="value">

View File

@ -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]
}
})

View File

@ -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);
}
}