question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

selectTranslate not available for lazy loaded translations if transloco pipe is not used

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
kmihalycommented, Nov 5, 2021

@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 😦

3reactions
rmcsharrycommented, May 27, 2020

Ok, my apologies, we are using scoped files (not one huge file) for translations, so if I provide the scope in the call

this.translocoService
  .selectTranslate(key, {}, 'testimonials')
  .subscribe(result => {
    console.log(result);
	})

then it works fine.

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found