tflori / angular-translator

translation module for angular
https://tflori.github.io/angular-translator/
MIT License
21 stars 6 forks source link

Add translator.translate method returning Observable #44

Closed BorntraegerMarc closed 7 years ago

BorntraegerMarc commented 7 years ago

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

BorntraegerMarc commented 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;
        });
tflori commented 7 years ago

@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.

tflori commented 7 years ago

You can still translate multiple items with this method:

translator.observeTranslate(['A','B']).subscribe((translations) => {
  this.a = translations[0];
  this.b = translations[1];
});
tflori commented 7 years ago

oh, one more thing: please don't use this version in production. the method might be changed.

BorntraegerMarc commented 7 years ago

I will test it out, thx!