Change language indicator

This commit is contained in:
Sean Engelhardt 2018-08-07 12:30:21 +02:00 committed by FinnStutzenstein
parent fcc5c008a1
commit cbb9185c2a
2 changed files with 19 additions and 9 deletions

View File

@ -97,8 +97,9 @@
<button mat-icon-button (click)='sideNav.toggle()'>
<fa-icon icon='ellipsis-v'></fa-icon>
</button>
<button mat-icon-button [matMenuTriggerFor]="languageMenu">
<fa-icon icon='language'></fa-icon>
<button mat-button [matMenuTriggerFor]="languageMenu">
<fa-icon icon='globe-americas'></fa-icon>
<span> {{getLangName(this.translate.currentLang)}} </span>
</button>
<!-- TODO: Could use translate.getLangs() to fetch available languages-->

View File

@ -29,6 +29,7 @@ export class SiteComponent extends BaseComponent implements OnInit {
* True if Viewport equals mobile or small resolution. Set by breakpointObserver.
*/
isMobile = false;
/**
* Constructor
*
@ -46,7 +47,7 @@ export class SiteComponent extends BaseComponent implements OnInit {
private operator: OperatorService,
private router: Router,
private breakpointObserver: BreakpointObserver,
protected translate: TranslateService,
public translate: TranslateService,
public dialog: MatDialog
) {
super();
@ -87,13 +88,21 @@ export class SiteComponent extends BaseComponent implements OnInit {
* Let the user change the language
* @param lang the desired language (en, de, fr, ...)
*/
selectLang(lang: string): void {
console.log('selected langauge: ', lang);
console.log('get Langs : ', this.translate.getLangs());
selectLang(selection: string): void {
this.translate.use(selection).subscribe();
}
this.translate.use(lang).subscribe(res => {
console.log('language changed : ', res);
});
/**
* Get the name of a Language by abbreviation.
*/
getLangName(abbreviation: string): string {
if (abbreviation === 'en') {
return this.translate.instant('English');
} else if (abbreviation === 'de') {
return this.translate.instant('German');
} else if (abbreviation === 'fr') {
return this.translate.instant('French');
}
}
/**