Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TranslateStore being created a second time causing no translations in lazy loaded module #1441

Open
pjc2007 opened this issue Jul 29, 2023 · 3 comments

Comments

@pjc2007
Copy link

pjc2007 commented Jul 29, 2023

Current behavior

I have outlined this here in this post, but not expecting much feed back from there.

In summary, as in the post, when loading my second lazy loaded module, I am seeing a second TranslateStore being created, and this being empty I get no translations. This has never happened before I upgraded to v15.0.0, and does not happen a small sample project, which makes it hard to demonstrate. I am doing exactly the same setup in the broken application as in a small sample app that works, so really have no idea of what is different to cause this (obviously my production application has a lot of other dependencies, but nothing else to do with translations)

I have spent a very long time trying to debug, but I just cannot see why a second TranslateStore is being created, as it goes very deep into the Angular DI code, which I just cant follow, so hoping there may be some suggestions on what could possibly cause this.

Expected behavior

To stop this second instance of TranslateStore being created so translation will one work in all modules.

How do you think that we should fix this?

I have no idea why the second TranslateStore is being created. I notice there is a always a new instance of TranslateService for each module being created, but this also occurs in a sample application where I do not have any problems

Environment


ngx-translate version: 15.0.0
Angular version:16.1.3

Browser:
- [ x] Chrome (desktop) version 115.0.5790.110
@skrilax91
Copy link

I have the exact same issue, on Angular 16. All my translations work outside lazy loaded modules but inside of it properties of TranslateService are undefined.

@pjc2007
Copy link
Author

pjc2007 commented Aug 31, 2023

My workaround has been to set a reference somewhere at startup (e.g. in a service) to translate.store

this.translator.use(hostInfo.locale);
this.translateStoreLoaderService.setStore(this.translator.store);

Then at the start (e.g. constructor) of each lazy component

translateStoreResetService.resetStore(translate);

with..

public setStore(translateStore: TranslateStore): void {   
    this.translateStore = translateStore;
}

public resetStore(translateService: TranslateService): void {   
   translateService.store = this.translateStore;   
}

The only way I could get it to work after trying many other things.

@skrilax91
Copy link

Your solution work perfectly !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants