I know that the following code doesn't work, because the translation file en.json
hasn't been loaded, when ngOnInit()
is called:
component.ts
ngOnInit() {
console.log(this.translocoService.translate('hello', { value: 'world' }););
}
en.json
{
"hello": "Hello",
}
An alternative would be subscribing to:
ngOnInit() {
this.translocoService.selectTranslate('hello', { value: 'world' }).subscribe(value => console.log(value));
}
But in my component I have 30 keys that need to be translated. Should I really subscribe to all of the 30 keys?
Demo: https://stackblitz.com/edit/ngneat-transloco-8xqjqm?file=src%2Fapp%2Fapp.component.ts