join/src/app/services/language.service.ts
2024-11-14 04:43:51 +01:00

27 lines
658 B
TypeScript

import { Injectable } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
@Injectable({
providedIn: 'root',
})
export class LanguageService {
currentLang = 'en';
constructor(private translate: TranslateService) {
this.translate.setDefaultLang(this.currentLang);
}
/**
* Switches the language for the application.
*
* @param lang A string denoting the language to switch to, either 'en' or 'de'.
*/
switchLanguage(lang: string) {
if (lang === 'en') {
this.currentLang = 'en';
} else if (lang == 'de') {
this.currentLang = 'de';
}
this.translate.use(this.currentLang);
}
}