selectTranslate not available for lazy loaded translations if transloco pipe is not used
See original GitHub issueI’m submitting a…
[ ] Regression (a behavior that used to work and stopped working in a new release)
[X] Bug report
[ ] Performance issue
[ ] Feature request
[ ] Documentation issue or request
[ ] Support request
[ ] Other... Please describe:
Current behavior
It is not possible to use selectTranslate in conjunction with lazy loaded translations without using the transloco pipe. The scope was specified in the providers, but for some reason it says that the translation key is missing. Also, if you do use the transloco pipe in the HTML, selectTranslate will still not (always) be available when you use it in ngOnInit hook. In the stackblitz below you can see the behavior if you go to /lazy-typescript-only
page.
https://stackblitz.com/edit/ngneat-transloco-issue
Expected behavior
selectTranslate should be available even if you don’t use the transloco pipe. Sometimes you need to translate strings within typescript without using the transloco pipe. Also selectTranslate returns an observable which should emit the translation once it’s available (perhaps wait for the file to be resolved before selectTranslate observable emits the translation). In the current situation the observables emits only one attempt which means that if the translation is not available at the time of subscribing, it will show a missing key warning.
Minimal reproduction of the problem with instructions
If you open the stackblitz:
https://stackblitz.com/edit/ngneat-transloco-issue
You can go to /lazy-typescript-only and if you look at the console you see the missing key warning while the file was specified in the module. If you uncomment the html snippet in the lazy-typescript-only component, you will see that the translation is available, but ONLY when you press the button.
What is the motivation / use case for changing the behavior?
To make this library better and bug-free
Environment
Angular version: 7
Browser:
- [X] Chrome (desktop) version XX
- [ ] Chrome (Android) version XX
- [ ] Chrome (iOS) version XX
- [ ] Firefox version XX
- [ ] Safari (desktop) version XX
- [ ] Safari (iOS) version XX
- [ ] IE version XX
- [ ] Edge version XX
For Tooling issues:
- Node version: XX
- Platform:
Others:
Issue Analytics
- State:
- Created 4 years ago
- Comments:12 (6 by maintainers)
@rmcsharry I am really grateful for your previous answer, since it saved us a lot of work hours. The documentation regarding this function is…well…it should be revised and completed 😦
Ok, my apologies, we are using scoped files (not one huge file) for translations, so if I provide the scope in the call
then it works fine.