ngx-translate / core

The internationalization (i18n) library for Angular
MIT License
4.51k stars 577 forks source link

Translate.get : When changing language, subscribers not notified . #677

Closed almgwary closed 6 years ago

almgwary commented 7 years ago

I'm submitting a bug report

[x] bug report =>  when changing language, subscribers not notified 

Current behavior when subscribe to translate.get() the subscription end automatically . check the next screen shot .

Expected/desired behavior i need to be still subscribing so when language change the code will rerun a again

Reproduction of the problem

this.translate.get('videoUrl').subscribe(
     (videoUrl:any)=>{
        console.log('i am a subscriber , changing video url ', videoUrl);
        // do this stuff when language change 
      },
      (e)=>{ console.error('i am a subscriber, this is error, ');},
      ()=>{ console.log('i am a subscriber , i am ended ');}
);

image

What is the expected behavior? i need to be still subscribing so when language change the code will rerun a again

What is the motivation / use case for changing the behavior? it will be awesome, my current situation, i change the video based on language and create some code configuration

Please tell us about your environment:

@angular/cli: 1.4.3
node: 7.7.3
os: win32 x64
almgwary commented 7 years ago

678

Kamilius commented 7 years ago

Same thing. In my case, I'm translating some strings using service instead of a pipe, so I need to automatically change this string if language was changed.

dennisroters commented 6 years ago

Use .stream() instead of .get()

https://github.com/ngx-translate/core#methods

Sampath-Lokuge commented 4 years ago

Thanks a lot @dennisroters It works.