robisim74 / angular-l10n

Angular library to translate texts, dates and numbers
MIT License
380 stars 59 forks source link

Lazy loading with initialNavigation enabled #301

Closed robisim74 closed 1 year ago

robisim74 commented 4 years ago

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 commented 4 years ago

@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.

nickroberts commented 4 years ago

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 commented 4 years ago

Looks like that property is required for SSR to work.

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

nickroberts commented 4 years ago

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

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

robisim74 commented 4 years ago

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

nickroberts commented 4 years ago

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!

robisim74 commented 4 years ago

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

Greetings

nickroberts commented 4 years ago

@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.

robisim74 commented 4 years ago

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

nickroberts commented 4 years ago

Looks good! Thanks!

robisim74 commented 1 year ago

Closed due to inactivity