fix translation init

This commit is contained in:
Paul Coral
2025-08-06 21:58:14 +02:00
parent 333fd824e3
commit fece4dcee1
4 changed files with 25 additions and 19 deletions

View File

@@ -3,6 +3,9 @@
"collection": "@nestjs/schematics", "collection": "@nestjs/schematics",
"sourceRoot": "src", "sourceRoot": "src",
"compilerOptions": { "compilerOptions": {
"deleteOutDir": true "deleteOutDir": true,
"assets": [
{ "include": "assets/**/*", "watchAssets": true }
]
} }
} }

View File

@@ -6,21 +6,24 @@ import * as i18nextBackend from 'i18next-fs-backend';
export const LOCALIZATION_SERVICE = 'LOCALIZATION_SERVICE'; export const LOCALIZATION_SERVICE = 'LOCALIZATION_SERVICE';
export const localizationServiceProvider: FactoryProvider = { export const localizationServiceProvider: FactoryProvider<LocalizationService> =
{
provide: LOCALIZATION_SERVICE, provide: LOCALIZATION_SERVICE,
scope: Scope.REQUEST, scope: Scope.REQUEST,
useFactory: async (req: Request) => { useFactory: async (req: Request) => {
const instance = i18next.createInstance().use(i18nextBackend as any); const instance = i18next.createInstance().use(i18nextBackend as any);
const supportedLang = const supportedLang = req
req.acceptsLanguages().find((l) => isSupportedLang(l)) ?? 'fr'; .acceptsLanguages()
.find((l) => isSupportedLang(l));
await instance.init<i18nextBackend.FsBackendOptions>({ await instance.init<i18nextBackend.FsBackendOptions>({
lng: supportedLang, lng: supportedLang,
debug: true, fallbackLng: 'en',
debug: false,
backend: { backend: {
loadPath: `${__dirname}/src/assets/i18n/{{lng}}.json`, loadPath: `assets/i18n/{{lng}}.json`,
}, },
}); });
new LocalizationService(instance); return new LocalizationService(instance);
}, },
inject: ['REQUEST'], inject: ['REQUEST'],
}; };