Add snackbar i18n usage + translations

pull/46/head
HardiReady 2018-10-05 15:51:46 +02:00
parent a24c8d3ac3
commit 18118d021e
16 changed files with 43 additions and 40 deletions

View File

@ -5,7 +5,6 @@ import {AppUserService} from '../services/app-user-service/app-user.service';
import {SquadService} from '../services/army-management/squad.service'; import {SquadService} from '../services/army-management/squad.service';
import {Fraction} from '../utils/fraction.enum'; import {Fraction} from '../utils/fraction.enum';
import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service'; import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service';
import {Message} from '../i18n/de.messages';
@Component({ @Component({
@ -47,7 +46,7 @@ export class AdminComponent implements OnInit {
this.appUserService.updateUser(updateObject) this.appUserService.updateUser(updateObject)
.subscribe(resUser => { .subscribe(resUser => {
this.snackBarService.showSuccess(Message.SUCCESS_SAVE); this.snackBarService.showSuccess("generic.save.success");
}); });
} }

View File

@ -1,5 +0,0 @@
export enum Message {
SIGN_UP_SUCCESS = 'Account erfolgreich erstellt',
SUCCESS_SAVE = 'Erfolgreich gespeichert',
DUPLICATED_NAME_ERR = 'Benutzername existiert bereits',
}

View File

@ -2,7 +2,6 @@ import {Component, OnInit} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router'; import {ActivatedRoute, Router} from '@angular/router';
import {LoginService} from '../services/app-user-service/login-service'; import {LoginService} from '../services/app-user-service/login-service';
import {RouteConfig} from '../app.config'; import {RouteConfig} from '../app.config';
import {Message} from '../i18n/de.messages';
import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service'; import {SnackBarService} from '../services/user-interface/snack-bar/snack-bar.service';
@ -38,11 +37,11 @@ export class SignupComponent implements OnInit {
.subscribe( .subscribe(
data => { data => {
this.loading = false; this.loading = false;
this.snackBarService.showSuccess(Message.SIGN_UP_SUCCESS); this.snackBarService.showSuccess('generic.signup.success');
}, },
error => { error => {
this.loading = false; this.loading = false;
this.snackBarService.showError(error, 10000); this.snackBarService.showError('generic.signup.error', 6000);
}); });
} }
} }

View File

@ -6,7 +6,6 @@ import {DecorationService} from '../../../services/army-management/decoration.se
import {Subscription} from 'rxjs/Subscription'; import {Subscription} from 'rxjs/Subscription';
import {Fraction} from '../../../utils/fraction.enum'; import {Fraction} from '../../../utils/fraction.enum';
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service'; import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
import {Message} from '../../../i18n/de.messages';
import {TranslateService} from '@ngx-translate/core'; import {TranslateService} from '@ngx-translate/core';
@Component({ @Component({
@ -89,7 +88,7 @@ export class EditDecorationComponent implements OnInit, OnDestroy {
this.imagePreviewSrc = 'resource/decoration/' + this.decoration._id + '.png?' + Date.now(); this.imagePreviewSrc = 'resource/decoration/' + this.decoration._id + '.png?' + Date.now();
}, 300); }, 300);
fileInput.value = ''; fileInput.value = '';
this.snackBarService.showSuccess(Message.SUCCESS_SAVE); this.snackBarService.showSuccess('generic.save.success');
}); });
} }
} }

View File

@ -5,7 +5,6 @@ import {Rank} from '../../../models/model-interfaces';
import {RankService} from '../../../services/army-management/rank.service'; import {RankService} from '../../../services/army-management/rank.service';
import {Subscription} from 'rxjs/Subscription'; import {Subscription} from 'rxjs/Subscription';
import {Fraction} from '../../../utils/fraction.enum'; import {Fraction} from '../../../utils/fraction.enum';
import {Message} from '../../../i18n/de.messages';
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service'; import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
import {TranslateService} from '@ngx-translate/core'; 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(); this.imagePreviewSrc = 'resource/rank/' + this.rank._id + '.png?' + Date.now();
}, 300); }, 300);
fileInput.value = ''; fileInput.value = '';
this.snackBarService.showSuccess(Message.SUCCESS_SAVE); this.snackBarService.showSuccess('generic.save.success');
}); });
} }
} }

View File

@ -6,7 +6,6 @@ import {SquadService} from '../../../services/army-management/squad.service';
import {Subscription} from 'rxjs/Subscription'; import {Subscription} from 'rxjs/Subscription';
import {Fraction} from '../../../utils/fraction.enum'; import {Fraction} from '../../../utils/fraction.enum';
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service'; import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
import {Message} from '../../../i18n/de.messages';
import {TranslateService} from '@ngx-translate/core'; 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(); this.imagePreviewSrc = 'resource/squad/' + this.squad._id + '.png?' + Date.now();
}, 300); }, 300);
fileInput.value = ''; fileInput.value = '';
this.snackBarService.showSuccess(Message.SUCCESS_SAVE); this.snackBarService.showSuccess('generic.save.success');
}); });
} }
} }

View File

@ -6,7 +6,6 @@ import {AwardingService} from '../../../services/army-management/awarding.servic
import {DecorationService} from '../../../services/army-management/decoration.service'; import {DecorationService} from '../../../services/army-management/decoration.service';
import {Fraction} from '../../../utils/fraction.enum'; import {Fraction} from '../../../utils/fraction.enum';
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service'; import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
import {Message} from '../../../i18n/de.messages';
import {TranslateService} from '@ngx-translate/core'; import {TranslateService} from '@ngx-translate/core';
@ -95,7 +94,7 @@ export class AwardUserComponent implements OnInit {
this.decoPreviewDisplay = 'none'; this.decoPreviewDisplay = 'none';
decorationField.value = undefined; decorationField.value = undefined;
reasonField.value = previewImage.src = descriptionField.innerHTML = ''; 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');
} }
} }

View File

@ -8,7 +8,6 @@ import {Subscription} from 'rxjs/Subscription';
import {NgForm} from '@angular/forms'; import {NgForm} from '@angular/forms';
import {Fraction} from '../../../utils/fraction.enum'; import {Fraction} from '../../../utils/fraction.enum';
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service'; import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
import {Message} from '../../../i18n/de.messages';
@Component({ @Component({
@ -100,18 +99,18 @@ export class EditUserComponent implements OnInit {
user.squad = '0'; user.squad = '0';
} }
this.user = user; this.user = user;
this.snackBarService.showSuccess(Message.SUCCESS_SAVE); this.snackBarService.showSuccess('generic.save.success');
}); });
} else { } else {
this.userService.submitUser(updateObject) this.userService.submitUser(updateObject)
.subscribe(user => { .subscribe(user => {
this.router.navigate(['..'], {relativeTo: this.route}); this.router.navigate(['..'], {relativeTo: this.route});
this.snackBarService.showSuccess(Message.SUCCESS_SAVE); this.snackBarService.showSuccess('generic.save.success');
return true; return true;
}, },
error => { error => {
// duplicated user error message // 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); this.snackBarService.showError(errorMessage, 10000);
}) })
} }

View File

@ -7,7 +7,6 @@ import {DecorationService} from '../../services/army-management/decoration.servi
import {UserService} from '../../services/army-management/user.service'; import {UserService} from '../../services/army-management/user.service';
import {LoginService} from '../../services/app-user-service/login-service'; import {LoginService} from '../../services/app-user-service/login-service';
import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service'; import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service';
import {Message} from '../../i18n/de.messages';
@Component({ @Component({
@ -94,7 +93,7 @@ export class RequestAwardComponent implements OnInit {
this.decoration = {_id: '0'}; this.decoration = {_id: '0'};
this.reason = previewImage.src = descriptionField.innerHTML = ''; this.reason = previewImage.src = descriptionField.innerHTML = '';
this.decoPreviewDisplay = 'none'; this.decoPreviewDisplay = 'none';
this.snackBarService.showSuccess(Message.SUCCESS_SAVE); this.snackBarService.showSuccess('generic.save.success');
}); });
}); });
} }

View File

@ -3,7 +3,6 @@ import {Award} from '../../models/model-interfaces';
import {AwardingService} from '../../services/army-management/awarding.service'; import {AwardingService} from '../../services/army-management/awarding.service';
import {LoginService} from '../../services/app-user-service/login-service'; import {LoginService} from '../../services/app-user-service/login-service';
import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service'; import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service';
import {Message} from '../../i18n/de.messages';
@Component({ @Component({
@ -47,7 +46,7 @@ export class ConfirmAwardComponent implements OnInit {
if (awards.length < 1) { if (awards.length < 1) {
this.awardingService.hasUnprocessedAwards = false; this.awardingService.hasUnprocessedAwards = false;
} }
this.snackBarService.showSuccess(Message.SUCCESS_SAVE); this.snackBarService.showSuccess('generic.save.success');
}); });
}); });
} }

View File

@ -4,7 +4,6 @@ import {RankService} from '../../services/army-management/rank.service';
import {PromotionService} from '../../services/army-management/promotion.service'; import {PromotionService} from '../../services/army-management/promotion.service';
import {LoginService} from '../../services/app-user-service/login-service'; import {LoginService} from '../../services/app-user-service/login-service';
import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service'; import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service';
import {Message} from '../../i18n/de.messages';
@Component({ @Component({
@ -51,7 +50,7 @@ export class ConfirmPromotionComponent implements OnInit {
if (promotions.length < 1) { if (promotions.length < 1) {
this.promotionService.hasUnprocessedPromotion = false; this.promotionService.hasUnprocessedPromotion = false;
} }
this.snackBarService.showSuccess(Message.SUCCESS_SAVE); this.snackBarService.showSuccess('generic.save.success');
}); });
}); });
} }

View File

@ -6,7 +6,6 @@ import {UserService} from '../../services/army-management/user.service';
import {RankService} from '../../services/army-management/rank.service'; import {RankService} from '../../services/army-management/rank.service';
import {PromotionService} from '../../services/army-management/promotion.service'; import {PromotionService} from '../../services/army-management/promotion.service';
import {LoginService} from '../../services/app-user-service/login-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'; import {SnackBarService} from '../../services/user-interface/snack-bar/snack-bar.service';
@ -80,7 +79,7 @@ export class RequestPromotionComponent implements OnInit {
this.uncheckedPromotions = promotions; this.uncheckedPromotions = promotions;
this.showForm = false; this.showForm = false;
this.user = {_id: '0'}; this.user = {_id: '0'};
this.snackBarService.showSuccess(Message.SUCCESS_SAVE); this.snackBarService.showSuccess('generic.save.success');
}); });
}); });
} }

View File

@ -1,9 +1,11 @@
import {Injectable} from '@angular/core'; import {Injectable} from '@angular/core';
import {MatSnackBar, MatSnackBarRef} from '@angular/material/snack-bar'; import {MatSnackBar, MatSnackBarRef} from '@angular/material/snack-bar';
import {TranslateService} from '@ngx-translate/core';
@Injectable() @Injectable()
export class SnackBarService { 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> { 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); return this.snackbar.open(message, action, config);
} }
showSuccess(message: string) { showSuccess(i18n: string) {
return this.show(message, undefined, 2500, ['custom-snack-bar', 'label-success']); this.translate.get(i18n).subscribe((translated) => {
return this.show(translated, undefined, 2500, ['custom-snack-bar', 'label-success']);
});
} }
showError(message: string, duration?: number) { showError(i18n: string, duration?: number) {
return this.show(message, 'OK', duration, ['custom-snack-bar', 'label-danger']); 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']);
});
});
} }
} }

View File

@ -4,7 +4,6 @@ import {NgForm} from '@angular/forms';
import {Subscription} from 'rxjs/Subscription'; import {Subscription} from 'rxjs/Subscription';
import {Campaign} from '../../../models/model-interfaces'; import {Campaign} from '../../../models/model-interfaces';
import {CampaignService} from '../../../services/logs/campaign.service'; import {CampaignService} from '../../../services/logs/campaign.service';
import {Message} from '../../../i18n/de.messages';
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service'; import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
@ -41,7 +40,7 @@ export class CampaignSubmitComponent {
if (this.campaign._id) { if (this.campaign._id) {
redirectSuccessUrl = '../' + redirectSuccessUrl; redirectSuccessUrl = '../' + redirectSuccessUrl;
} }
this.snackBarService.showSuccess(Message.SUCCESS_SAVE); this.snackBarService.showSuccess('generic.save.success');
this.router.navigate([redirectSuccessUrl + campaign._id], {relativeTo: this.route}); this.router.navigate([redirectSuccessUrl + campaign._id], {relativeTo: this.route});
}, },
error => this.snackBarService.showError(error._body.error.message, 15000)); error => this.snackBarService.showError(error._body.error.message, 15000));

View File

@ -49,5 +49,11 @@
"public.army.member.headline": "Auszeichnungen von {{name}}", "public.army.member.headline": "Auszeichnungen von {{name}}",
"public.army.member.awards.title": "Bezeichnung", "public.army.member.awards.title": "Bezeichnung",
"public.army.member.awards.reason": "Begründung", "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"
} }

View File

@ -48,5 +48,11 @@
"public.army.member.headline": "Awards of {{name}}", "public.army.member.headline": "Awards of {{name}}",
"public.army.member.awards.title": "Title", "public.army.member.awards.title": "Title",
"public.army.member.awards.reason": "Reason", "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"
} }