gilsdav / ngx-translate-router

Translate routes using ngx-translate
131 stars 43 forks source link

Angular Standalone API #154

Closed gilsdav closed 8 months ago

gilsdav commented 1 year ago

Create a standalone API for this library.

Current API:

RouterModule.forRoot(routes),
LocalizeRouterModule.forRoot(routes, {
    parser: {
      provide: LocalizeParser,
      useFactory: HttpLoaderFactory,
      deps: [TranslateService, Location, LocalizeRouterSettings, HttpClient]
    },
    cacheMechanism: CacheMechanism.Cookie,
    cookieFormat: '{{value}};{{expires:20}};path=/',
})

New API

provideRouter(routes, withLocalizeRouter(routes, {
  parser: {
    provide: LocalizeParser,
    useFactory: HttpLoaderFactory,
    deps: [TranslateService, Location, LocalizeRouterSettings, HttpClient]
  },
  cacheMechanism: CacheMechanism.Cookie,
  cookieFormat: '{{value}};{{expires:20}};path=/',
}))

To make it fully compatible with standalone API we also need to change the pipe to make it standalone.

gilsdav commented 1 year ago

Follow https://github.com/gilsdav/ngx-translate-router/pull/155

gilsdav commented 12 months ago

Hello @ruizmarc Can you help me to check if it works well in a fully standalone and SSR app ?

gilsdav commented 12 months ago

Example usage here: https://github.com/gilsdav/angular-universal-localize-router/blob/angular-17/projects/standalone/src/app/app.config.ts

gilsdav commented 12 months ago

published using version 7.1.0-rc1

ruizmarc commented 11 months ago

Hi,

Sorry for my late reply, the end of year brings a lot of work to me… but I’m finally here!

I will try to add SSR to the demo project, in this way it will be easier to test any change in the future.

Testing changes in SSR for this package requires to setup a new project with SSR and publishing a new version of the package or linking your local one and reproducing all test cases, which is not so convenient for development… I think that integrating SSR to the demo project it will make things easier to everyone that wants to contribute as now it is much easier to develop in SSR as angular provides a development SSR server with live reload, so no extra setup is required to test it :)

I will open a PR to the standalone-api branch so I can test SSR while adding SSR to the project.

ruizmarc commented 11 months ago

Hi @gilsdav,

All done in this PR: https://github.com/gilsdav/ngx-translate-router/pull/158

I also tested the new Standalone API, as I'm forking from that branch, and it seems to work fine in both browser and SSR :)

Happy new year :)

gilsdav commented 8 months ago

Published as version 7.1.0. Thank's again @ruizmarc.