Compare commits

...

2 Commits

Author SHA1 Message Date
HardiReady 18118d021e Add snackbar i18n usage + translations 2018-10-05 15:51:46 +02:00
HardiReady a24c8d3ac3 Add flag dropdown for language selection 2018-10-05 13:01:51 +02:00
22 changed files with 94 additions and 63 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 {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");
});
}

View File

@ -89,21 +89,6 @@
</ul>
<ul class="nav navbar-nav pull-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false">
Language
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li>
<a (click)="setLanguage('en')">English</a>
</li>
<li>
<a (click)="setLanguage('de')">Deutsch</a>
</li>
</ul>
</li>
<li *ngIf="loginService.hasPermission(4)" routerLinkActive="active">
<a routerLink='{{config.adminPanelPath}}' class="link">{{'navigation.top.admin' | translate}}</a>
</li>
@ -113,6 +98,18 @@
<li *ngIf="!loginService.isLoggedIn()" routerLinkActive="active">
<a routerLink='{{config.loginPath}}' class="link">{{'navigation.top.login' | translate}}</a>
</li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true"
aria-expanded="false" style="padding: 12px 12px 10px 12px;">
<mat-icon svgIcon="{{(language === 'de') ? 'flag-de' : 'flag-gb'}}"></mat-icon>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li *ngFor="let lang of languages" style="cursor: pointer">
<a (click)="setLanguage(lang)"><mat-icon svgIcon="{{(lang === 'de') ? 'flag-de' : 'flag-gb'}}"></mat-icon></a>
</li>
</ul>
</li>
</ul>
</div>
</div>

View File

@ -6,7 +6,7 @@ import {AwardingService} from './services/army-management/awarding.service';
import {RouteConfig} from './app.config';
import {DOCUMENT} from '@angular/common';
import {DomSanitizer} from '@angular/platform-browser';
import {MatIconRegistry} from '@angular/material';
import {MatIconRegistry, MatSelectChange} from '@angular/material';
import {SpinnerService} from './services/user-interface/spinner/spinner.service';
import {TranslateService} from '@ngx-translate/core';
import {SettingsService} from './services/settings.service';
@ -55,8 +55,15 @@ export class AppComponent implements OnInit {
'vehicleAir': 'stats/scoreboard/vehicleAir',
'vehicleHeavy': 'stats/scoreboard/vehicleHeavy',
'vehicleLight': 'stats/scoreboard/vehicleLight',
// --------LOCALE---------
'flag-de': 'locale/de',
'flag-gb': 'locale/gb',
};
language;
languages = ['de', 'en'];
version = 'v'.concat(require('./../../../package.json').version);
constructor(public loginService: LoginService,
@ -90,7 +97,10 @@ export class AppComponent implements OnInit {
}
ngOnInit() {
this.settingsService.getLanguage().subscribe((language) => this.translate.setDefaultLang(language));
this.settingsService.getLanguage().subscribe((language) => {
this.language = language;
this.translate.setDefaultLang(language)
});
if (this.loginService.hasPermission(2)) {
const fraction = this.loginService.getCurrentUser().squad.fraction;
this.promotionService.checkUnconfirmedPromotions(fraction);
@ -104,8 +114,7 @@ export class AppComponent implements OnInit {
initMaterialSvgIcons() {
Object.keys(this.svgIcons).forEach(key => {
const fileUri = '../assets/icon/'.concat(this.svgIcons[key])
.concat('.svg');
const fileUri = '../assets/icon/'.concat(this.svgIcons[key]).concat('.svg');
this.iconRegistry.addSvgIcon(key, this.sanitizer.bypassSecurityTrustResourceUrl(fileUri));
});
}
@ -130,6 +139,7 @@ export class AppComponent implements OnInit {
setLanguage(language: string) {
if (language) {
this.language = language;
this.settingsService.setLanguage(language);
}
}

View File

@ -24,7 +24,7 @@ import {CookieService} from 'ngx-cookie-service';
import {SnackBarService} from './services/user-interface/snack-bar/snack-bar.service';
import {HttpClientModule} from '@angular/common/http';
import {SpinnerService} from './services/user-interface/spinner/spinner.service';
import {MatSnackBarModule} from '@angular/material';
import {MatSelectModule, MatSnackBarModule} from '@angular/material';
import {HttpClient} from './services/http-client';
import {SettingsService} from './services/settings.service';
@ -38,6 +38,7 @@ import {SettingsService} from './services/settings.service';
HttpClientModule,
ClipboardModule,
MatSnackBarModule,
MatSelectModule,
],
providers: [

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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"
}

View File

@ -7,10 +7,10 @@
"public.error.message.default": "{{fieldName}} is not valid",
"public.common.search.button": "Search",
"navigation.top.board": "To message board",
"navigation.top.board": "To Message Board",
"navigation.top.overview": "Army Overview",
"navigation.top.ranks": "Ranks",
"navigation.top.decorations": "Awards",
"navigation.top.decorations": "Decorations",
"navigation.top.statistics": "Statistics",
"navigation.top.login": "Login",
"navigation.top.logout": "Logout",
@ -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"
}

View File

@ -17,7 +17,7 @@
"stats.sidebar.overview": "Overview",
"stats.sidebar.highscore": "Highscore",
"stats.sidebar.battles": "Battles",
"stats.sidebar.battles.battle.from.date": "at",
"stats.sidebar.battles.battle.from.date": "of",
"stats.sidebar.battle.manage.edit": "Edit",
"stats.sidebar.battle.manage.delete": "Delete",
"stats.sidebar.battle.manage.delete.confirm": "Do you really want to delete the battle \"{{title}}\"?",

View File

@ -0,0 +1,5 @@
<svg xmlns="http://www.w3.org/2000/svg" id="flag-icon-css-de" viewBox="0 0 640 480">
<path fill="#ffce00" d="M0 320h640v160H0z"/>
<path fill="#000" d="M0 0h640v160H0z"/>
<path fill="#d00" d="M0 160h640v160H0z"/>
</svg>

After

Width:  |  Height:  |  Size: 225 B

View File

@ -0,0 +1,15 @@
<svg xmlns="http://www.w3.org/2000/svg" id="flag-icon-css-gb" viewBox="0 0 640 480">
<defs>
<clipPath id="a">
<path fill-opacity=".7" d="M-85.3 0h682.6v512H-85.3z"/>
</clipPath>
</defs>
<g clip-path="url(#a)" transform="translate(80) scale(.94)">
<g stroke-width="1pt">
<path fill="#006" d="M-256 0H768v512H-256z"/>
<path fill="#fff" d="M-256 0v57.2L653.5 512H768v-57.2L-141.5 0H-256zM768 0v57.2L-141.5 512H-256v-57.2L653.5 0H768z"/>
<path fill="#fff" d="M170.7 0v512h170.6V0H170.7zM-256 170.7v170.6H768V170.7H-256z"/>
<path fill="#c00" d="M-256 204.8v102.4H768V204.8H-256zM204.8 0v512h102.4V0H204.8zM-256 512L85.3 341.3h76.4L-179.7 512H-256zm0-512L85.3 170.7H9L-256 38.2V0zm606.4 170.7L691.7 0H768L426.7 170.7h-76.3zM768 512L426.7 341.3H503l265 132.5V512z"/>
</g>
</g>
</svg>

After

Width:  |  Height:  |  Size: 831 B