How to use angular prerendering with transloco?

160 views Asked by At

When i prerender my angular app, i've no translation text visible with transloco, because it use http to get data from asset/i18n/en.json.

How to use prerendering with dynamic translation ?

1

There are 1 answers

0
Tim On

Final implem for me.

const initializeLangFactory = (lang: LangService, http: HttpClient) => {
  return () =>
    http.get<Translation>(
      `${environment.baseUrl}/assets/i18n/${lang.initializeLang()}.json`
    );
};

export const provideLangInitializer = () => {
  return {
    provide: APP_INITIALIZER,
    useFactory: initializeLangFactory,
    deps: [LangService, HttpClient],
    multi: true,
  };
};

LangService get activeLang : navigator.language > localstorage.lang > transloco.activeLang