I'm using nestjs-i18n version 8.0.2 on my NestJS project to internationalize the strings.
I have a class in one of my modules that has this constructor:
constructor(
@InjectRepository(UsersRepository)
private readonly usersRepository: UsersRepository,
private readonly apiService: ApiService,
private readonly i18n: I18nRequestScopeService,
) {
}
This is the full class:
@QueryHandler(MyQuery)
export class MyQueryHandler implements IQueryHandler<MyQuery> {
constructor(
@InjectRepository(UsersRepository)
private readonly usersRepository: UsersRepository,
private readonly apiService: ApiService,
private readonly i18n: I18nRequestScopeService,
) {
}
async execute(query: MyQuery): Promise<MyResult> {
...
}
}
QueryHandler is a decorator from the cqrs library @nestjs/cqrs version 6.1.0, if this can be of any help.
For some reason, my 3 dependencies are undefined if I try to inject I18nRequestScopeService as shown, but usersRepository and apiService are correctly defined if I remove the I18nRequestScopeService injection.
No warnings or errors are shown on the log.
I have a custom ExceptionFilter with this constructor:
constructor(private readonly i18n: I18nRequestScopeService) {
}
and it works just fine.
In app.module.ts I have this:
@Module({
imports: [
...
I18nModule.forRoot({
fallbackLanguage: 'en',
parser: I18nJsonParser,
parserOptions: {
path: path.join(__dirname, 'i18n/'),
},
resolvers: [
{ use: QueryResolver, options: ['lang', 'locale', 'l'] },
new HeaderResolver(['x-custom-lang']),
AcceptLanguageResolver,
new CookieResolver(['lang', 'locale', 'l']),
],
})
],
...
})
I tried googling for the problem, but I had no luck. What am I missing?