Romanchuk / angular-i18next

angular v10+ integration with i18next v19.4+
MIT License
131 stars 33 forks source link

Change Language without reloading page #96

Closed centigrade-julian-lang closed 1 year ago

centigrade-julian-lang commented 1 year ago

Hi, I am new to i18next and your package - so sorry if this question is somehow obvious to solve or something. :)

I want to change the displayed language on the fly (so without reloading the page; in order to keep application-state). After digging a bit into the code, I saw that the I18NextPipe is marked as pure: true (implicitly, by omitting the property).

As I understand it, this means that Angular will only evaluate the value for each translation-key once, caches this value and after it reuses the cached value for further requests for that specific key. If so, this would make something like a live-change of the language, practically impossible.

Am I correct, and is there any way or plan to enable a dynamic language change without reloading?

Btw, I tried this code, but it did not work, unfortunately:

class MyAngularComponent {
   // gets called as event handler from template:
   async changeLang(lang: string) {
      await this.i18NextService.changeLanguage(lang);
      this.changeDetectorRef.detectChanges();
      // commented the reload out:
      // document.location.reload();
   }
}

Thanks in advance!

Romanchuk commented 1 year ago

@centigrade-julian-lang Hi, i18nextEager made for that. Look information at repos readme.md file

centigrade-julian-lang commented 1 year ago

@Romanchuk Thank you a lot :)