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

Messages are compiled multiple times on initial load #955

Closed
Yirica opened this issue Nov 5, 2018 · 0 comments · Fixed by #956
Closed

Messages are compiled multiple times on initial load #955

Yirica opened this issue Nov 5, 2018 · 0 comments · Fixed by #956

Comments

@Yirica
Copy link

Yirica commented Nov 5, 2018

Current behavior

When an application is loaded initially the translations are compiled for every subscription to translateService.get on the current page because the translations are still pending when the observables are created.

The initial loading of the translations is triggered by calling translateService.setDefaultLang() in the app.component.ts. When translateService.get is called afterwards it re-compiles the translations in the subscription, because the initial loading is still pending (https://github.com/ngx-translate/core/blob/master/projects/ngx-translate/core/src/lib/translate.service.ts#L372).

Expected behavior

Translations are only compiled once.

How do you think that we should fix this?

loadingTranslations could be set to an observable returning the compiled translations (maybe by piping a map in getTranslation(). Keep the return value of the method the same observable but set loadingTranslations to an observable with the piped map)

Minimal reproduction of the problem with instructions

https://stackblitz.com/edit/github-kr4c1v
Every call to compile writes a message to the console

Environment


ngx-translate version: 10.0.2
Angular version: 6.1.7

Browser:
- All, independent of the browser and version
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

Successfully merging a pull request may close this issue.

1 participant