angular-l10n icon indicating copy to clipboard operation
angular-l10n copied to clipboard

Lazy loading with initialNavigation enabled

Open robisim74 opened this issue 5 years ago • 10 comments

I am getting a weird error, as well, when lazy loading translations from a project created with nx.

core.js:6189
ERROR Error: Uncaught (in promise): angular-l10n (formatLanguage): Invalid language
    at resolvePromise (zone-evergreen.js:798)
    at resolvePromise (zone-evergreen.js:750)
    at zone-evergreen.js:860
    at ZoneDelegate.invokeTask (zone-evergreen.js:399)
    at Object.onInvokeTask (core.js:41442)
    at ZoneDelegate.invokeTask (zone-evergreen.js:398)
    at Zone.runTask (zone-evergreen.js:167)
    at drainMicroTaskQueue (zone-evergreen.js:569)

What's weird, is that it works fine with the exact same code when I just create a project with the Angular CLI.

Looks like there might be some issues with running an Nx project in StackBlitz. Here is a pristine project that was generated with nx on StackBlitz.

If this can't be figured out, I'm going to move away from using Nx. I like it, but I think I can get most of what I want done with just the Angular CLI (multiple projects / libraries).

Originally posted by @nickroberts in https://github.com/robisim74/angular-l10n/issues/295#issuecomment-612272480

robisim74 avatar Apr 11 '20 12:04 robisim74

@nickroberts Your app built with nx has a difference: use initialNavigation: 'enabled' in the router: if I remove it, the app works (also the reloading of the lazy module).

However, it should work also with initial navigation, so there must be something else in the app, but it doesn't depend on nx anyway.

robisim74 avatar Apr 11 '20 15:04 robisim74

Ah! That's it! At least as to why the Nx one doesn't work.I added that to the ng version, and it broke, too. Thanks for the insight! Might need to look into why that option isn't working for angular-l10n.

Thanks! Also, thanks for migrating this to a separate issue. I guess you can either close this, or if you want to investigate why that option is breaking the library, that's cool.

Keep up the great work!

nickroberts avatar Apr 11 '20 17:04 nickroberts

Looks like that property is required for SSR to work.

https://angular.io/api/router/InitialNavigation

nickroberts avatar Apr 11 '20 17:04 nickroberts

Looks like the router has its own APP_INITIALIZER, as well.

https://github.com/angular/angular/issues/36263#issuecomment-610671572

nickroberts avatar Apr 11 '20 18:04 nickroberts

The strange thing is that in the sample app of this project, the option works (but without L10nRouting).

About SSR, never used that option.

However I'll continue to investigate, and let you know here.

Greetings

robisim74 avatar Apr 11 '20 18:04 robisim74

Yea, I haven't used Angular Universal (SSR), either, but would love to be able to use that option if we need to. I'll let you know if I find out anything else. Thanks!

nickroberts avatar Apr 11 '20 18:04 nickroberts

@nickroberts I fixed initialNavigation in the latest version: https://github.com/robisim74/angular-l10n/releases/tag/v9.2.0

Greetings

robisim74 avatar Apr 14 '20 16:04 robisim74

@robisim74 It looks like this is back with version 10.0.1. 10.0.0 works, but after updating, and lazy loading translations, it no longer loads the lazy loaded translations ifinitialNavigation is enabled.

nickroberts avatar Jul 28 '20 20:07 nickroberts

@nickroberts Thanks for reporting the problem (again). Fixed in v10.0.2

robisim74 avatar Jul 29 '20 13:07 robisim74

Looks good! Thanks!

nickroberts avatar Jul 29 '20 14:07 nickroberts

Closed due to inactivity

robisim74 avatar May 14 '23 07:05 robisim74