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

How to use extends (and/or) isolate to provide translations at the component/lazy-loaded module level? #1501

Open
piotaixr opened this issue Nov 7, 2024 · 1 comment

Comments

@piotaixr
Copy link

piotaixr commented Nov 7, 2024

Current behavior

Translations provided at a component level are not detected. Language change is also not propagated to "nested" translate services.

Expected behavior

The nested component to have access to both the translation at the root, and the translation loaded by the child module in its providers.
I was also expecting the language change at the root to be propagated upwards.

How do you think that we should fix this?

The TranslateService seems to not have enouth code to handle the case where additional loaders are provided after initialization.

Minimal reproduction of the problem with instructions

I added a failing test case in my fork here: https://github.com/piotaixr/ngx-translate-core/tree/bug/extends

Environment

Default branch of the project
Everything else ic coming from the repo config

Browser:
Chrome desktop

For Tooling issues:

  • Node version: 22.11
  • Platform: Mac + Linux

@piotaixr piotaixr changed the title How to use extends (and/or) isolate to provide translations at the component/lazt-loaded module level? How to use extends (and/or) isolate to provide translations at the component/lazy-loaded module level? Nov 7, 2024
@CodeAndWeb
Copy link
Member

Isolate means that the instance you create is completely independent from the other ones. I've inspected the code so far... isolate should work as it is. The implementation is not perfect and I've refactored it 7b72914

However the extend feature seems indeed broken. I am not sure if this happened during changes for v16 or was broken before. It seems that there were no tests for this use-case - thanks for providing one.

I would say that a language change should propagate to all instances of the translate service that are shared and not isolated.

I am not yet sure about the behaviour of the extend feature. setTranslations() merges the translations in the shared main store. use() is somehow designed to also merge them into the main store if extend is set - but does not uses a flat merge instead of mergeDeep()... this is one thing that has to be fixed for sure.

I just wonder, if merging is a good idea. The disadvantage is that components using the same key would overwrite the translations for all.
Another option instead would be to create some kind of augmentation. In a component, would check its "local" store first for translations and fall back to the root store if missing. This would allow using the same ID in multiple components.

The bigger issue for me is that I have no idea who is relying on the current behaviour and what side effects changes might make...

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

No branches or pull requests

2 participants