fix translation init
This commit is contained in:
@@ -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 }
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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'],
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user