Add error messages i18n
parent
0adb9b7cf9
commit
4eef29bd05
|
@ -1,5 +1,6 @@
|
||||||
import {Component, Input} from '@angular/core';
|
import {Component, Input, OnInit} from '@angular/core';
|
||||||
import {FormGroup, NgForm} from '@angular/forms';
|
import {FormGroup, NgForm} from '@angular/forms';
|
||||||
|
import {TranslateService} from '@ngx-translate/core';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'show-error',
|
selector: 'show-error',
|
||||||
|
@ -10,7 +11,7 @@ import {FormGroup, NgForm} from '@angular/forms';
|
||||||
</div>
|
</div>
|
||||||
</div>`
|
</div>`
|
||||||
})
|
})
|
||||||
export class ShowErrorComponent {
|
export class ShowErrorComponent implements OnInit{
|
||||||
|
|
||||||
// tslint:disable-next-line:no-input-rename
|
// tslint:disable-next-line:no-input-rename
|
||||||
@Input('controlPath') controlPath;
|
@Input('controlPath') controlPath;
|
||||||
|
@ -20,10 +21,15 @@ export class ShowErrorComponent {
|
||||||
|
|
||||||
private form: FormGroup;
|
private form: FormGroup;
|
||||||
|
|
||||||
constructor(ngForm: NgForm) {
|
constructor(ngForm: NgForm,
|
||||||
|
private translate: TranslateService) {
|
||||||
this.form = ngForm.form;
|
this.form = ngForm.form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ngOnInit() {
|
||||||
|
this.translate.setDefaultLang('de');
|
||||||
|
}
|
||||||
|
|
||||||
get errorMessages(): string[] {
|
get errorMessages(): string[] {
|
||||||
const control = this.form.get(this.controlPath);
|
const control = this.form.get(this.controlPath);
|
||||||
const messages = [];
|
const messages = [];
|
||||||
|
@ -37,22 +43,43 @@ export class ShowErrorComponent {
|
||||||
let message = '';
|
let message = '';
|
||||||
switch (code) {
|
switch (code) {
|
||||||
case 'required':
|
case 'required':
|
||||||
message = `${this.displayName} ist ein Pflichtfeld`;
|
this.translate.get('public.error.message.required', {fieldName: this.displayName})
|
||||||
|
.subscribe((res: string) => {
|
||||||
|
message = res;
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case 'minlength':
|
case 'minlength':
|
||||||
message = `${this.displayName} muss mindestens ${error.requiredLength} Zeichen enthalten`;
|
this.translate.get('public.error.message.min.length', {
|
||||||
|
fieldName: this.displayName,
|
||||||
|
boundary: error.requiredLength
|
||||||
|
})
|
||||||
|
.subscribe((res: string) => {
|
||||||
|
message = res;
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case 'maxlength':
|
case 'maxlength':
|
||||||
message = `${this.displayName} darf maximal ${error.requiredLength} Zeichen enthalten`;
|
this.translate.get('public.error.message.max.length', {
|
||||||
|
fieldName: this.displayName,
|
||||||
|
boundary: error.requiredLength
|
||||||
|
})
|
||||||
|
.subscribe((res: string) => {
|
||||||
|
message = res;
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case 'invalidEMail':
|
case 'invalidEMail':
|
||||||
message = `Bitte geben Sie eine gültige E-Mail Adresse an`;
|
this.translate.get('public.error.message.email').subscribe((res: string) => {
|
||||||
|
message = res;
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
case 'userNotFound':
|
case 'userNotFound':
|
||||||
message = `Der eingetragene Benutzer existiert nicht.`;
|
this.translate.get('public.error.message.no.user').subscribe((res: string) => {
|
||||||
|
message = res;
|
||||||
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
message = `${name} ist nicht valide`;
|
this.translate.get('public.error.message.default', {fieldName: name}).subscribe((res: string) => {
|
||||||
|
message = res;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
messages.push(message);
|
messages.push(message);
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,5 +34,12 @@
|
||||||
"public.army.headline": "Übersicht über alle Spieler, Squads und Armeen",
|
"public.army.headline": "Übersicht über alle Spieler, Squads und Armeen",
|
||||||
"public army.squad.members": "Mitglieder:",
|
"public army.squad.members": "Mitglieder:",
|
||||||
"public.army.members": "Armeemitglieder:",
|
"public.army.members": "Armeemitglieder:",
|
||||||
"public.error.headline": "Oops, diese Seite kennen wir nicht..."
|
"public.error.headline": "Oops, diese Seite kennen wir nicht...",
|
||||||
|
|
||||||
|
"public.error.message.required": "{{fieldName}} ist ein Pflichtfeld",
|
||||||
|
"public.error.message.min.length": "{{fieldName}} muss mindestens {{boundary}} Zeichen enthalten",
|
||||||
|
"public.error.message.max.length": "{{fieldName}} darf maximal {{boundary}} Zeichen enthalten",
|
||||||
|
"public.error.message.email": "Bitte geben Sie eine gültige E-Mail Adresse an",
|
||||||
|
"public.error.message.no.user": "Der eingetragene Benutzer existiert nicht.",
|
||||||
|
"public.error.message.default": "{{fieldName}} ist nicht valide"
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,5 +72,12 @@
|
||||||
"stats.campaign.submit.headline.edit": "Kampagne editieren",
|
"stats.campaign.submit.headline.edit": "Kampagne editieren",
|
||||||
"stats.campaign.submit.title": "Titel",
|
"stats.campaign.submit.title": "Titel",
|
||||||
"stats.campaign.submit.button.submit": "Bestätigen",
|
"stats.campaign.submit.button.submit": "Bestätigen",
|
||||||
"stats.campaign.submit.button.cancel": "Abbrechen"
|
"stats.campaign.submit.button.cancel": "Abbrechen",
|
||||||
|
|
||||||
|
"public.error.message.required": "{{fieldName}} ist ein Pflichtfeld",
|
||||||
|
"public.error.message.min.length": "{{fieldName}} muss mindestens {{boundary}} Zeichen enthalten",
|
||||||
|
"public.error.message.max.length": "{{fieldName}} darf maximal {{boundary}} Zeichen enthalten",
|
||||||
|
"public.error.message.email": "Bitte geben Sie eine gültige E-Mail Adresse an",
|
||||||
|
"public.error.message.no.user": "Der eingetragene Benutzer existiert nicht.",
|
||||||
|
"public.error.message.default": "{{fieldName}} ist nicht valide"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue