ngx-translate/core

Angular 18 Support SSR

aparzi opened this issue · 9 comments

Is translation supported for Angular 18 SSR?

It seems to work. however for me it renders the translations on server side, then when the client loads it in it re loads the translations, causing a small flicker.

Might be my configuration

Hi @cskiwi,
It seems to work for me too. Flickering effect should it could depend hydration process of Angular.

Indeed was some configuration on my part. all is resolved now

@cskiwi Could you at least share that fix for others?

I am suffering from that flickering too.

Hi @KariNarhi28,
can you share the code? Because flickering effect depends on Hydration process of Angular. I don't think that an issue of ngx-translate

@KariNarhi28 and @aparzi. it's hard to narrow down the exact fix because it didn't bother me that much and did some other changes first and eventually it was resolved.

If I would guess it would have been one of the following changes:

I had my own Transtion Module that intializes everything with a .forRoot(config). I removed that and switched to:

export const appConfig: ApplicationConfig = {
  providers: [
    provideHttpClient(withFetch(), withInterceptorsFromDi()),
    importProvidersFrom(
      TranslateModule.forRoot(
        provideTranslation({
          api: `/api/v1/translate/i18n/`,
        }),
      ),
    )
  ]
}

with the following provider:

export const provideTranslation = (config: ITranslateConfig) => ({
  defaultLanguage: 'en',
  useDefaultLang: true,
  loader: {
    provide: TranslateLoader,
    useFactory: (http: HttpClient, baseUrl: string) =>
      new TranslateHttpLoader(http, baseUrl + config.api, ''),
    deps: [HttpClient, BASE_URL],
  },
});

I also moved my languageIntializer to the privders in the app.config.ts.
However none of these should have impact this

@cskiwi you should add provideClientHydration() in app.module. More informations in this guide: https://angular.dev/guide/hydration.

Screenshot 2024-07-30 alle 11 44 36

@aparzi it is there :) i just didn't copy all my providers. But still thanks for spotting that!