I'm writing an app with Angular 8 and NativeScript 6.4.1.
I am considering using Transloco for my translations library.
I need to be able to change the language at runtime as well as add a new language at runtime.
How can I do this in Transloco?
I see in the docs it says you can add a language with the setLanguage
function: https://ngneat.github.io/transloco/docs/language-api
I tried it myself and it doesn't work.
Here is my sample project: https://github.com/aubrey-fowler/Transloco-Test
Here is a code snippet:
export class ItemsComponent implements OnInit {
constructor(private translate: TranslocoService) { }
ngOnInit(): void {
console.log(' ItemsComponent ', this.translate.getActiveLang());
console.log(' ItemsComponent 2 ', this.translate.getAvailableLangs());
}
switchLang(lang: string) {
this.translate.setActiveLang(lang);
console.log(' setActiveLang ', this.translate.getActiveLang());
}
useLanguage(language: string) {
this.translate.setActiveLang(language);
console.log(' setActiveLang ', this.translate.getActiveLang());
}
add() {
console.log(' a ');
this.translate.setTranslation({ Sitetitle : "bonjour"}, 'fr', { merge: true });
console.log(' ItemsComponent ', this.translate.getActiveLang());
console.log(' ItemsComponent 3 ', this.translate.getAvailableLangs());
}
}