Open DongFang-Jun opened 3 weeks ago
import { DynamicModule } from '@nestjs/common'; import { join } from 'path'; import { I18nModule as i18n, HeaderResolver } from 'nestjs-i18n'; import { ConfigService } from '@nestjs/config';
export class I18nModule { static forRootAsync(): DynamicModule { const rootPath = join(__dirname, '..', '..', '..'); return i18n.forRootAsync({ inject: [ConfigService], resolvers: [new HeaderResolver(['lang'])], // 请求头匹配 useFactory: (configService: ConfigService) => ({ fallbackLanguage: configService.get('i18n.fallbackLanguage'), // 默认语言 loaderOptions: { path: ${rootPath}${configService.get<string>('i18n.path')}, // 翻译文件位置 watch: configService.get('i18n.watch'), // 将选项设置watch为可true启用loaderOptions实时重新加载 }, }), }); } }
${rootPath}${configService.get<string>('i18n.path')}
no
"nestjs-i18n": "^10.4.5", "i18next": "^23.14.0", "i18next-fs-backend": "^2.3.2", "i18next-http-middleware": "^3.6.0",
pnpm
Describe the bug
import { DynamicModule } from '@nestjs/common'; import { join } from 'path'; import { I18nModule as i18n, HeaderResolver } from 'nestjs-i18n'; import { ConfigService } from '@nestjs/config';
export class I18nModule { static forRootAsync(): DynamicModule { const rootPath = join(__dirname, '..', '..', '..'); return i18n.forRootAsync({ inject: [ConfigService], resolvers: [new HeaderResolver(['lang'])], // 请求头匹配 useFactory: (configService: ConfigService) => ({ fallbackLanguage: configService.get('i18n.fallbackLanguage'), // 默认语言 loaderOptions: { path:('i18n.watch'), // 将选项设置watch为可true启用loaderOptions实时重新加载
},
}),
});
}
}
${rootPath}${configService.get<string>('i18n.path')}
, // 翻译文件位置 watch: configService.getReproduction
no
System Info
Used Package Manager
pnpm
Validations