-
-
Notifications
You must be signed in to change notification settings - Fork 202
Bug(transloco): Lazy Loading Transloco Scopes Not Working in Component Logic #820
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
Comments
I am also facing this issue. Please address it when possible. |
Please read the docs:
|
I have reviewed the documentation thoroughly, and I noticed that the issue I am encountering is also present in the main demo of the library. I’ve added a comment highlighting the issue inside the lazy.component.ts file in the following CodeSandbox: Could you kindly review this and provide a recommended solution? |
I have added the following section to make it work for the first time:
|
The current method is inefficient as it requires repetition in each lazy-loaded module. |
I encountered a similar issue with loading translations for multiple modules in Transloco. I resolved it by using forkJoin to combine the translation requests. Is there a plan to address this problem or provide an alternative solution? |
@saeidi-dev is right, with lazy loading, even if translations are loaded before the initialization of the component, the service (method .translate) does not find the translations (at least, in the constructor block) |
My bad, the issue is resolved for me The issue was that the TranslocoService was provided in the lazy component |
I have demonstrated this issue in the main Transloco demo. If you manage to implement this correctly using the provideTranslocoScope function without any problems, please share a CodeSandbox link. |
Any eta of this problem please, it's very a problem of this nice library |
I'll try to find some time to address this, if someone wants to take a shot at this you're welcome to open a PR 🙌 |
Because I had to take a detailed look on scoped translations, I came across this issue. For me it seem that the issue @saeidi-dev tries to show in the CodeSandbox Link just proves what @shaharkazaz already mentioned in the FAQ. If you want to use the translations in the component you could take a look at the "translateSignal" method, which also automatically detects the current scope. |
Uh oh!
There was an error while loading. Please reload this page.
Is there an existing issue for this?
Which Transloco package(s) are the source of the bug?
Transloco
Is this a regression?
Yes
Current behavior
When using the TranslocoService to fetch translations in a lazy-loaded component, the translations are not resolved, and the following error occurs:
Missing translation for 'adminPage.title'.
This happens even though the provideTranslocoScope function is correctly configured in the LAZY_ROUTES file with the scope admin-page. The translations are displayed properly in the template using the transloco structural directive, but the same keys are missing when accessed programmatically via TranslocoService.translate() in the component logic.
1.Define lazy routes as follows:
2.Create a lazy-loaded component (LazyComponent) with the following logic:
3. html template:
Observed Behavior:
The template correctly displays the translation for adminPage.title.
In the console, the following error appears:
Missing translation for 'adminPage.title'.
Expected behavior
The translation key adminPage.title should resolve successfully in the component logic when using TranslocoService.translate().
This issue was also observed in the official Transloco demo on CodeSandbox:
Transloco Demo - Lazy Scope Issue
Please provide a link to a minimal reproduction of the bug, if you won't provide a link the issue won't be handled.
https://codesandbox.io/s/jsverse-transloco-kn52hs
Transloco Config
No response
Please provide the environment you discovered this bug in
Browser
No response
Additional context
No response
I would like to make a pull request for this bug
Yes 🚀
The text was updated successfully, but these errors were encountered: