Minor language service refactor

This commit is contained in:
softsimon 2022-01-12 19:08:56 +04:00
parent efffd1a929
commit c8d38740cc
No known key found for this signature in database
GPG Key ID: 488D7DCFB5A430D7

View File

@ -11,10 +11,12 @@ export class LanguageService {
constructor( constructor(
@Inject(DOCUMENT) private document: Document, @Inject(DOCUMENT) private document: Document,
@Inject(LOCALE_ID) private locale: string, @Inject(LOCALE_ID) private locale: string,
) { } ) {
this.language = getLocaleId(this.locale).substring(0, 2);
}
getLanguage(): string { getLanguage(): string {
return getLocaleId(this.locale).substring(0, 2); return this.language;
} }
stripLanguageFromUrl(urlPath: string) { stripLanguageFromUrl(urlPath: string) {
@ -27,12 +29,10 @@ export class LanguageService {
} }
getLanguageForUrl(): string { getLanguageForUrl(): string {
let lang = this.getLanguage(); return this.language === 'en' ? '' : '/' + this.language;
return lang === 'en' ? '' : '/' + lang;
} }
setLanguage(language: string): void { setLanguage(language: string): void {
this.language = language;
try { try {
document.cookie = `lang=${language}; expires=Thu, 18 Dec 2050 12:00:00 UTC; path=/`; document.cookie = `lang=${language}; expires=Thu, 18 Dec 2050 12:00:00 UTC; path=/`;
} catch (e) { } } catch (e) { }