Transloco: Scoped translations only loaded for the last imported module

Created on 17 Dec 2019  路  4Comments  路  Source: ngneat/transloco

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

  • import multiple Modules
  • each of this Modules have their own translation scope.

Problem: Scoped Translations only loaded for the last imported module.

Expected behavior

Load translations for all modules with an own translation scope.

Minimal reproduction of the problem with instructions

You can reproduce this bug in this example app:
https://stackblitz.com/edit/ngneat-transloco-etbm6n

If you change the import import order for AlertModule and ModalModule in the app.module.ts File, the missing translations will changed.

Environment

Angular version: 8.2.14

Browser:

  • [x] Chrome (desktop) version XX

All 4 comments

I have recently written a blog that covers all this topic, you will find your answer here:
https://medium.com/@ItayOded/lazy-load-and-encapsulate-i18n-files-in-angular-with-transloco-55af44885797

@itayod can you please reopen this issue.

The problem still exists with the demo repo from your blog (https://medium.com/@ItayOded/lazy-load-and-encapsulate-i18n-files-in-angular-with-transloco-55af44885797).

In my fork repo https://github.com/gernsdorfer/transloco-files-management/tree/translations-with-multiple-dependencies you can reproduce this behaviour.

Depending of the import order in the module file (
https://github.com/gernsdorfer/transloco-files-management/blob/translations-with-multiple-dependencies/apps/transloco-files-management/src/app/from-scoped-lib/from-scoped-lib.module.ts) the translations only works for the last imported module (ModuleB or LazyTranslationsModule).

Hi @gernsdorfer what you are describing is the way that Angular's DI works. We had several issues opened before about the same phenomena and we are tired of reexplaining that over and over...
Please read how the DI works with lazy / eager loaded modules or you can find it as mentioned in my blog:

Like every other provider, scopes also follow the Angular DI rules. Therefore if we use an eager module that declares a scope, in a module feature that also declares one, the feature module鈥檚 scope will run over the eager module鈥檚.

For others facing the same issue, to summirize no, you can't use multiple modules for scopes

Was this page helpful?
0 / 5 - 0 ratings