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
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:
@@ -20,10 +20,6 @@ import {
|
|||||||
TranslateModule,
|
TranslateModule,
|
||||||
TranslateService,
|
TranslateService,
|
||||||
} from '@ngx-translate/core';
|
} from '@ngx-translate/core';
|
||||||
import {
|
|
||||||
provideTranslateHttpLoader,
|
|
||||||
TranslateHttpLoader,
|
|
||||||
} from '@ngx-translate/http-loader';
|
|
||||||
import { adminAuthInterceptor } from './core/interceptors/admin-auth.interceptor';
|
import { adminAuthInterceptor } from './core/interceptors/admin-auth.interceptor';
|
||||||
import {
|
import {
|
||||||
provideClientHydration,
|
provideClientHydration,
|
||||||
@@ -31,6 +27,7 @@ import {
|
|||||||
} from '@angular/platform-browser';
|
} from '@angular/platform-browser';
|
||||||
import { serverOriginInterceptor } from './core/interceptors/server-origin.interceptor';
|
import { serverOriginInterceptor } from './core/interceptors/server-origin.interceptor';
|
||||||
import { catchError, firstValueFrom, of } from 'rxjs';
|
import { catchError, firstValueFrom, of } from 'rxjs';
|
||||||
|
import { StaticTranslateLoader } from './core/i18n/static-translate.loader';
|
||||||
|
|
||||||
type SupportedLang = 'it' | 'en' | 'de' | 'fr';
|
type SupportedLang = 'it' | 'en' | 'de' | 'fr';
|
||||||
const SUPPORTED_LANGS: readonly SupportedLang[] = ['it', 'en', 'de', 'fr'];
|
const SUPPORTED_LANGS: readonly SupportedLang[] = ['it', 'en', 'de', 'fr'];
|
||||||
@@ -61,16 +58,12 @@ export const appConfig: ApplicationConfig = {
|
|||||||
provideHttpClient(
|
provideHttpClient(
|
||||||
withInterceptors([serverOriginInterceptor, adminAuthInterceptor]),
|
withInterceptors([serverOriginInterceptor, adminAuthInterceptor]),
|
||||||
),
|
),
|
||||||
provideTranslateHttpLoader({
|
|
||||||
prefix: './assets/i18n/',
|
|
||||||
suffix: '.json',
|
|
||||||
}),
|
|
||||||
importProvidersFrom(
|
importProvidersFrom(
|
||||||
TranslateModule.forRoot({
|
TranslateModule.forRoot({
|
||||||
defaultLanguage: 'it',
|
defaultLanguage: 'it',
|
||||||
loader: {
|
loader: {
|
||||||
provide: TranslateLoader,
|
provide: TranslateLoader,
|
||||||
useClass: TranslateHttpLoader,
|
useClass: StaticTranslateLoader,
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
),
|
),
|
||||||
|
|||||||
25
frontend/src/app/core/i18n/static-translate.loader.ts
Normal file
25
frontend/src/app/core/i18n/static-translate.loader.ts
Normal 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']);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,6 +14,7 @@
|
|||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"experimentalDecorators": true,
|
"experimentalDecorators": true,
|
||||||
"moduleResolution": "bundler",
|
"moduleResolution": "bundler",
|
||||||
|
"resolveJsonModule": true,
|
||||||
"importHelpers": true,
|
"importHelpers": true,
|
||||||
"target": "ES2022",
|
"target": "ES2022",
|
||||||
"module": "ES2022"
|
"module": "ES2022"
|
||||||
|
|||||||
Reference in New Issue
Block a user