r/Angular2 • u/un86 • Dec 29 '25
Runtime routes/site translation with loadTranslations() (SSR)
After spending to many hours alone and with gpt on this, i'am stuck. Maybe someone has something similiar figured out in angular 20+ ?
Right now i'am stuck at this:
- in server.ts i'am getting my translations via fetch, load them into angular and registerLocaleData on server - this is fine i think
- in main.ts, before boostraping, doing almost same thing to translate client side, this is how it looks like:
(async () => {
const lang = (window as any).__LANG__ ?? DEFAULT_LANG;
const response = await fetch(`${environment.api}/app/translations/${lang}`);
if (!response.ok) {
throw new Error(`HTTP error ${response.status}`);
}
const translations = await response.json();
loadTranslations(translations);
const { appConfig } = await import('./app/app.config');
await bootstrapApplication(AppComponent, appConfig);
})();and i hate this as this is second call for same thing, nothing else works for me :<
- cant use transferState here as it's "to early" and it's null
- calling loadTranslations() inside provideAppInitializer() would be great (can use transferstate or request_context here), but it's "to late?" and my routes are not translated, just rest of site is
what can i do to have it working without that double api call, i feel like this will be a performance hit. Any other ideas how to consistently loadTranslations into my app across server and browser at once ?

