Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

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

Bug(scope): Scoping doesn't work in routes loaded with loadChildren #776

Closed
1 task done
CitrusyAlmond opened this issue Jun 26, 2024 · 3 comments
Closed
1 task done

Comments

@CitrusyAlmond
Copy link

CitrusyAlmond commented Jun 26, 2024

Is there an existing issue for this?

  • I have searched the existing issues

Which Transloco package(s) are the source of the bug?

Transloco

Is this a regression?

Yes

Current behavior

The function provideTranslocoScope only applies the scopes assigned to the parent element. It doesn't seem to work either in the lazy loaded route file nor the child component's Type Decorator.

This is a screenshot of the main routes file.
image

This is a screenshot of the child routes file.
image

When using this._transloco.getTranslation(), it only shows the translations from the language.json file as well as those from the scope assigned in the parent element.

image

Expected behavior

The function provideTranslocoScope to not also apply the scopes assigned to it in the main routes file, but also those imported using the loadChildren function.

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/tmt5zn

Transloco Config

No response

Please provide the environment you discovered this bug in

Transloco: 
Angular: 
Node: 
Package Manager: 
OS:

Browser

No response

Additional context

No response

I would like to make a pull request for this bug

No

@shaharkazaz
Copy link
Collaborator

The issue with your reproduction is that you are not triggering a load for the lazy translation set.
When you use the transloco pipe in the main template, he triggers a load for the scoped translation. that's why we see that the translations for main are loading while the lazy ones are missing.

@CitrusyAlmond
Copy link
Author

CitrusyAlmond commented Jun 27, 2024

You are absolutely right, the use of the transloco pipe was dowloading the translation file, which could be read by the child component.

That said, after removing the template translation I find myself unable to load the provided scope without directly referencing it in the selectTranslate function, most likely due to a lack of understanding of the explanations given.

With a routes file such as this.
image

I encounter myself in this situation.
image

After using selectTranslate to bring the scope, any further translation of main.message will work. While this is fine when working with a singular scope, it causes problems when trying to work with multiple, as I'd have to use selectTranslate for each individual scope.

I apologize if my question might seem stupid, but I'm failing to come up with the solution to the issue.

@shaharkazaz
Copy link
Collaborator

@CitrusyAlmond There are no stupid questions 🙂

I'm trying to understand your use-case though. Do you only need translations inside the components? Transloco's loading mechanism was intended to be internal and not managed by the consumers. If you further explain your use-case I can maybe assist more.

Also, take a look at the preload langs plugin, it might be what you are looking for or you can take inspiration from the implementation code.

@jsverse jsverse locked and limited conversation to collaborators Jul 12, 2024
@shaharkazaz shaharkazaz converted this issue into discussion #783 Jul 12, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants