Closed BorntraegerMarc closed 7 years ago
So basically the use case would be instead of having:
translator.translate('title').then((translation) => {
this.title = translation;
});
translator.languageChanged.subscribe(() => {
translator.translate('title').then((translation) => {
this.title = translation;
});
});
We would just have:
translator.translate('title').subscribe((translation) => {
this.title = translation;
});
@BorntraegerMarc you might want to give 2.2.0-alpha.1 a try. There is a new method observeTranslate(keys, params?)
.
Other than translate this method returns an observerable that gets new values when a new language got loaded. Also this method does not accept the language parameter for obvious reasons.
You can still translate multiple items with this method:
translator.observeTranslate(['A','B']).subscribe((translations) => {
this.a = translations[0];
this.b = translations[1];
});
oh, one more thing: please don't use this version in production. the method might be changed.
I will test it out, thx!
Maybe we could replace the translator.translate('TEXT') from returning a promise to an observable. That way the UI would always automatically update when TranslatorContainer changes the language.
Or add an additional one