Last active
April 7, 2019 13:51
-
-
Save theodesp/6f0350a671fe3032e49b812564843044 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { ITranslationService, I18NEXT_SERVICE } from 'angular-i18next'; | |
import { Component, ViewEncapsulation, Inject, OnInit } from '@angular/core'; | |
@Component({ | |
selector: 'header-language', | |
encapsulation: ViewEncapsulation.None, | |
templateUrl: './header.component.html', | |
}) | |
export class HeaderComponent implements OnInit { | |
language = 'en'; | |
languages: string[] = ['en', 'el']; | |
constructor( | |
@Inject(I18NEXT_SERVICE) private i18NextService: ITranslationService | |
) {} | |
ngOnInit() { | |
this.i18NextService.events.initialized.subscribe((e) => { | |
if (e) { | |
this.updateState(this.i18NextService.language); | |
} | |
}); | |
} | |
changeLanguage(lang: string){ | |
if (lang !== this.i18NextService.language) { | |
this.i18NextService.changeLanguage(lang).then(x => { | |
this.updateState(lang); | |
document.location.reload(); | |
}); | |
} | |
} | |
private updateState(lang: string) { | |
this.language = lang; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment