import { inject } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';

export function initializeTranslations() {
    const translate = inject(TranslateService);

    const availableLangs = ['de', 'at', 'en'];
    translate.addLangs(availableLangs);

    const defaultLang = 'de';
    let langToUse = translate.getBrowserLang() ?? defaultLang;
    langToUse = availableLangs.includes(langToUse) ? langToUse : defaultLang;

    translate.setFallbackLang(defaultLang);
    translate.use(langToUse);

    document.documentElement.lang = langToUse;
    
    translate.onLangChange.subscribe((event) => {
      document.documentElement.lang = event.lang;
    });
}
