fix(front-end): ssr i18n fix
All checks were successful
Build and Deploy / test-backend (push) Successful in 27s
Build and Deploy / test-frontend (push) Successful in 1m1s
Build and Deploy / build-and-push (push) Successful in 29s
Build and Deploy / deploy (push) Successful in 21s
PR Checks / prettier-autofix (pull_request) Successful in 11s
PR Checks / security-sast (pull_request) Successful in 30s
PR Checks / test-backend (pull_request) Successful in 27s
PR Checks / test-frontend (pull_request) Successful in 59s

This commit is contained in:
2026-03-11 17:27:28 +01:00
parent 5bb23fbcfa
commit fd4104da39
3 changed files with 28 additions and 9 deletions

View File

@@ -20,10 +20,6 @@ import {
TranslateModule,
TranslateService,
} from '@ngx-translate/core';
import {
provideTranslateHttpLoader,
TranslateHttpLoader,
} from '@ngx-translate/http-loader';
import { adminAuthInterceptor } from './core/interceptors/admin-auth.interceptor';
import {
provideClientHydration,
@@ -31,6 +27,7 @@ import {
} from '@angular/platform-browser';
import { serverOriginInterceptor } from './core/interceptors/server-origin.interceptor';
import { catchError, firstValueFrom, of } from 'rxjs';
import { StaticTranslateLoader } from './core/i18n/static-translate.loader';
type SupportedLang = 'it' | 'en' | 'de' | 'fr';
const SUPPORTED_LANGS: readonly SupportedLang[] = ['it', 'en', 'de', 'fr'];
@@ -61,16 +58,12 @@ export const appConfig: ApplicationConfig = {
provideHttpClient(
withInterceptors([serverOriginInterceptor, adminAuthInterceptor]),
),
provideTranslateHttpLoader({
prefix: './assets/i18n/',
suffix: '.json',
}),
importProvidersFrom(
TranslateModule.forRoot({
defaultLanguage: 'it',
loader: {
provide: TranslateLoader,
useClass: TranslateHttpLoader,
useClass: StaticTranslateLoader,
},
}),
),

View File

@@ -0,0 +1,25 @@
import { Injectable } from '@angular/core';
import {
TranslateLoader,
TranslationObject,
} from '@ngx-translate/core';
import { Observable, of } from 'rxjs';
import de from '../../../assets/i18n/de.json';
import en from '../../../assets/i18n/en.json';
import fr from '../../../assets/i18n/fr.json';
import it from '../../../assets/i18n/it.json';
const TRANSLATIONS: Record<string, TranslationObject> = {
it: it as TranslationObject,
en: en as TranslationObject,
de: de as TranslationObject,
fr: fr as TranslationObject,
};
@Injectable()
export class StaticTranslateLoader implements TranslateLoader {
getTranslation(lang: string): Observable<TranslationObject> {
const normalized = String(lang || 'it').toLowerCase();
return of(TRANSLATIONS[normalized] ?? TRANSLATIONS['it']);
}
}