Add snackbar i18n usage + translations
parent
a24c8d3ac3
commit
18118d021e
|
@ -5,7 +5,6 @@ import {AppUserService} from '../services/app-user-service/app-user.service';
|
|||
import {SquadService} from '../services/army-management/squad.service';
|
||||
import {Fraction} from '../utils/fraction.enum';
|
||||
import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service';
|
||||
import {Message} from '../i18n/de.messages';
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -47,7 +46,7 @@ export class AdminComponent implements OnInit {
|
|||
|
||||
this.appUserService.updateUser(updateObject)
|
||||
.subscribe(resUser => {
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess("generic.save.success");
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +0,0 @@
|
|||
export enum Message {
|
||||
SIGN_UP_SUCCESS = 'Account erfolgreich erstellt',
|
||||
SUCCESS_SAVE = 'Erfolgreich gespeichert',
|
||||
DUPLICATED_NAME_ERR = 'Benutzername existiert bereits',
|
||||
}
|
|
@ -2,7 +2,6 @@ import {Component, OnInit} from '@angular/core';
|
|||
import {ActivatedRoute, Router} from '@angular/router';
|
||||
import {LoginService} from '../services/app-user-service/login-service';
|
||||
import {RouteConfig} from '../app.config';
|
||||
import {Message} from '../i18n/de.messages';
|
||||
import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service';
|
||||
|
||||
|
||||
|
@ -38,11 +37,11 @@ export class SignupComponent implements OnInit {
|
|||
.subscribe(
|
||||
data => {
|
||||
this.loading = false;
|
||||
this.snackBarService.showSuccess(Message.SIGN_UP_SUCCESS);
|
||||
this.snackBarService.showSuccess('generic.signup.success');
|
||||
},
|
||||
error => {
|
||||
this.loading = false;
|
||||
this.snackBarService.showError(error, 10000);
|
||||
this.snackBarService.showError('generic.signup.error', 6000);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import {DecorationService} from '../../../services/army-management/decoration.se
|
|||
import {Subscription} from 'rxjs/Subscription';
|
||||
import {Fraction} from '../../../utils/fraction.enum';
|
||||
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
|
||||
import {Message} from '../../../i18n/de.messages';
|
||||
import {TranslateService} from '@ngx-translate/core';
|
||||
|
||||
@Component({
|
||||
|
@ -89,7 +88,7 @@ export class EditDecorationComponent implements OnInit, OnDestroy {
|
|||
this.imagePreviewSrc = 'resource/decoration/' + this.decoration._id + '.png?' + Date.now();
|
||||
}, 300);
|
||||
fileInput.value = '';
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import {Rank} from '../../../models/model-interfaces';
|
|||
import {RankService} from '../../../services/army-management/rank.service';
|
||||
import {Subscription} from 'rxjs/Subscription';
|
||||
import {Fraction} from '../../../utils/fraction.enum';
|
||||
import {Message} from '../../../i18n/de.messages';
|
||||
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
|
||||
import {TranslateService} from '@ngx-translate/core';
|
||||
|
||||
|
@ -93,7 +92,7 @@ export class EditRankComponent implements OnInit, OnDestroy {
|
|||
this.imagePreviewSrc = 'resource/rank/' + this.rank._id + '.png?' + Date.now();
|
||||
}, 300);
|
||||
fileInput.value = '';
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import {SquadService} from '../../../services/army-management/squad.service';
|
|||
import {Subscription} from 'rxjs/Subscription';
|
||||
import {Fraction} from '../../../utils/fraction.enum';
|
||||
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
|
||||
import {Message} from '../../../i18n/de.messages';
|
||||
import {TranslateService} from '@ngx-translate/core';
|
||||
|
||||
|
||||
|
@ -93,7 +92,7 @@ export class EditSquadComponent implements OnInit, OnDestroy {
|
|||
this.imagePreviewSrc = 'resource/squad/' + this.squad._id + '.png?' + Date.now();
|
||||
}, 300);
|
||||
fileInput.value = '';
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import {AwardingService} from '../../../services/army-management/awarding.servic
|
|||
import {DecorationService} from '../../../services/army-management/decoration.service';
|
||||
import {Fraction} from '../../../utils/fraction.enum';
|
||||
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
|
||||
import {Message} from '../../../i18n/de.messages';
|
||||
import {TranslateService} from '@ngx-translate/core';
|
||||
|
||||
|
||||
|
@ -95,7 +94,7 @@ export class AwardUserComponent implements OnInit {
|
|||
this.decoPreviewDisplay = 'none';
|
||||
decorationField.value = undefined;
|
||||
reasonField.value = previewImage.src = descriptionField.innerHTML = '';
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
@ -113,7 +112,7 @@ export class AwardUserComponent implements OnInit {
|
|||
});
|
||||
});
|
||||
});
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import {Subscription} from 'rxjs/Subscription';
|
|||
import {NgForm} from '@angular/forms';
|
||||
import {Fraction} from '../../../utils/fraction.enum';
|
||||
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
|
||||
import {Message} from '../../../i18n/de.messages';
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -100,18 +99,18 @@ export class EditUserComponent implements OnInit {
|
|||
user.squad = '0';
|
||||
}
|
||||
this.user = user;
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
});
|
||||
} else {
|
||||
this.userService.submitUser(updateObject)
|
||||
.subscribe(user => {
|
||||
this.router.navigate(['..'], {relativeTo: this.route});
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
return true;
|
||||
},
|
||||
error => {
|
||||
// duplicated user error message
|
||||
const errorMessage = error._body.includes('duplicate') ? Message.DUPLICATED_NAME_ERR : error._body;
|
||||
const errorMessage = error._body.includes('duplicate') ? 'generic.signup.error.duplicate' : error._body;
|
||||
this.snackBarService.showError(errorMessage, 10000);
|
||||
})
|
||||
}
|
||||
|
|
|
@ -7,7 +7,6 @@ import {DecorationService} from '../../services/army-management/decoration.servi
|
|||
import {UserService} from '../../services/army-management/user.service';
|
||||
import {LoginService} from '../../services/app-user-service/login-service';
|
||||
import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service';
|
||||
import {Message} from '../../i18n/de.messages';
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -94,7 +93,7 @@ export class RequestAwardComponent implements OnInit {
|
|||
this.decoration = {_id: '0'};
|
||||
this.reason = previewImage.src = descriptionField.innerHTML = '';
|
||||
this.decoPreviewDisplay = 'none';
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ import {Award} from '../../models/model-interfaces';
|
|||
import {AwardingService} from '../../services/army-management/awarding.service';
|
||||
import {LoginService} from '../../services/app-user-service/login-service';
|
||||
import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service';
|
||||
import {Message} from '../../i18n/de.messages';
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -47,7 +46,7 @@ export class ConfirmAwardComponent implements OnInit {
|
|||
if (awards.length < 1) {
|
||||
this.awardingService.hasUnprocessedAwards = false;
|
||||
}
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import {RankService} from '../../services/army-management/rank.service';
|
|||
import {PromotionService} from '../../services/army-management/promotion.service';
|
||||
import {LoginService} from '../../services/app-user-service/login-service';
|
||||
import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service';
|
||||
import {Message} from '../../i18n/de.messages';
|
||||
|
||||
|
||||
@Component({
|
||||
|
@ -51,7 +50,7 @@ export class ConfirmPromotionComponent implements OnInit {
|
|||
if (promotions.length < 1) {
|
||||
this.promotionService.hasUnprocessedPromotion = false;
|
||||
}
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -6,7 +6,6 @@ import {UserService} from '../../services/army-management/user.service';
|
|||
import {RankService} from '../../services/army-management/rank.service';
|
||||
import {PromotionService} from '../../services/army-management/promotion.service';
|
||||
import {LoginService} from '../../services/app-user-service/login-service';
|
||||
import {Message} from '../../i18n/de.messages';
|
||||
import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service';
|
||||
|
||||
|
||||
|
@ -80,7 +79,7 @@ export class RequestPromotionComponent implements OnInit {
|
|||
this.uncheckedPromotions = promotions;
|
||||
this.showForm = false;
|
||||
this.user = {_id: '0'};
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
import {Injectable} from '@angular/core';
|
||||
import {MatSnackBar, MatSnackBarRef} from '@angular/material/snack-bar';
|
||||
import {TranslateService} from '@ngx-translate/core';
|
||||
|
||||
@Injectable()
|
||||
export class SnackBarService {
|
||||
constructor(private snackbar: MatSnackBar) {
|
||||
constructor(private snackbar: MatSnackBar,
|
||||
private translate: TranslateService) {
|
||||
}
|
||||
|
||||
private show(message: string, action?: string, duration?: number, panelClasses?: string[]): MatSnackBarRef<any> {
|
||||
|
@ -27,11 +29,17 @@ export class SnackBarService {
|
|||
return this.snackbar.open(message, action, config);
|
||||
}
|
||||
|
||||
showSuccess(message: string) {
|
||||
return this.show(message, undefined, 2500, ['custom-snack-bar', 'label-success']);
|
||||
showSuccess(i18n: string) {
|
||||
this.translate.get(i18n).subscribe((translated) => {
|
||||
return this.show(translated, undefined, 2500, ['custom-snack-bar', 'label-success']);
|
||||
});
|
||||
}
|
||||
|
||||
showError(message: string, duration?: number) {
|
||||
return this.show(message, 'OK', duration, ['custom-snack-bar', 'label-danger']);
|
||||
showError(i18n: string, duration?: number) {
|
||||
this.translate.get(i18n).subscribe((translated) => {
|
||||
this.translate.get('generic.snackbar.error.button.okay').subscribe((translatedOkay) => {
|
||||
return this.show(translated, translatedOkay, duration, ['custom-snack-bar', 'label-danger']);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import {NgForm} from '@angular/forms';
|
|||
import {Subscription} from 'rxjs/Subscription';
|
||||
import {Campaign} from '../../../models/model-interfaces';
|
||||
import {CampaignService} from '../../../services/logs/campaign.service';
|
||||
import {Message} from '../../../i18n/de.messages';
|
||||
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
|
||||
|
||||
|
||||
|
@ -41,7 +40,7 @@ export class CampaignSubmitComponent {
|
|||
if (this.campaign._id) {
|
||||
redirectSuccessUrl = '../' + redirectSuccessUrl;
|
||||
}
|
||||
this.snackBarService.showSuccess(Message.SUCCESS_SAVE);
|
||||
this.snackBarService.showSuccess('generic.save.success');
|
||||
this.router.navigate([redirectSuccessUrl + campaign._id], {relativeTo: this.route});
|
||||
},
|
||||
error => this.snackBarService.showError(error._body.error.message, 15000));
|
||||
|
|
|
@ -49,5 +49,11 @@
|
|||
"public.army.member.headline": "Auszeichnungen von {{name}}",
|
||||
"public.army.member.awards.title": "Bezeichnung",
|
||||
"public.army.member.awards.reason": "Begründung",
|
||||
"public.army.member.awards.date": "Verliehen am"
|
||||
"public.army.member.awards.date": "Verliehen am",
|
||||
|
||||
"generic.save.success": "Erfolgreich gespeichert",
|
||||
"generic.snackbar.error.button.okay": "OK",
|
||||
"generic.signup.success": "Account erfolgreich erstellt",
|
||||
"generic.signup.error.duplicate": "Benutzername existiert bereits",
|
||||
"generic.signup.error": "Es ist ein Fehler aufgetreten"
|
||||
}
|
||||
|
|
|
@ -48,5 +48,11 @@
|
|||
"public.army.member.headline": "Awards of {{name}}",
|
||||
"public.army.member.awards.title": "Title",
|
||||
"public.army.member.awards.reason": "Reason",
|
||||
"public.army.member.awards.date": "Decorated at"
|
||||
"public.army.member.awards.date": "Decorated at",
|
||||
|
||||
"generic.save.success": "Saved successfully",
|
||||
"generic.snackbar.error.button.okay": "OK",
|
||||
"generic.signup.success": "Account creation successful",
|
||||
"generic.signup.error.duplicate": "Username does already exist",
|
||||
"generic.signup.error": "An error occurred"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue