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 {TranslateService} from '@ngx-translate/core';
|
||||
|
||||
@Component({
|
||||
selector: 'show-error',
|
||||
|
@ -10,7 +11,7 @@ import {FormGroup, NgForm} from '@angular/forms';
|
|||
</div>
|
||||
</div>`
|
||||
})
|
||||
export class ShowErrorComponent {
|
||||
export class ShowErrorComponent implements OnInit{
|
||||
|
||||
// tslint:disable-next-line:no-input-rename
|
||||
@Input('controlPath') controlPath;
|
||||
|
@ -20,10 +21,15 @@ export class ShowErrorComponent {
|
|||
|
||||
private form: FormGroup;
|
||||
|
||||
constructor(ngForm: NgForm) {
|
||||
constructor(ngForm: NgForm,
|
||||
private translate: TranslateService) {
|
||||
this.form = ngForm.form;
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.translate.setDefaultLang('de');
|
||||
}
|
||||
|
||||
get errorMessages(): string[] {
|
||||
const control = this.form.get(this.controlPath);
|
||||
const messages = [];
|
||||
|
@ -37,22 +43,43 @@ export class ShowErrorComponent {
|
|||
let message = '';
|
||||
switch (code) {
|
||||
case 'required':
|
||||
message = `${this.displayName} ist ein Pflichtfeld`;
|
||||
this.translate.get('public.error.message.required', {fieldName: this.displayName})
|
||||
.subscribe((res: string) => {
|
||||
message = res;
|
||||
});
|
||||
break;
|
||||
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;
|
||||
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;
|
||||
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;
|
||||
case 'userNotFound':
|
||||
message = `Der eingetragene Benutzer existiert nicht.`;
|
||||
this.translate.get('public.error.message.no.user').subscribe((res: string) => {
|
||||
message = res;
|
||||
});
|
||||
break;
|
||||
default:
|
||||
message = `${name} ist nicht valide`;
|
||||
this.translate.get('public.error.message.default', {fieldName: name}).subscribe((res: string) => {
|
||||
message = res;
|
||||
});
|
||||
}
|
||||
messages.push(message);
|
||||
}
|
||||
|
|
|
@ -34,5 +34,12 @@
|
|||
"public.army.headline": "Übersicht über alle Spieler, Squads und Armeen",
|
||||
"public army.squad.members": "Mitglieder:",
|
||||
"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.title": "Titel",
|
||||
"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