I would like to retrieve a property in the dictionary. I'm trying to do everything according to the documentation using the i18nValidationMessage function. Unfortunately, I'm not getting the appropriate translation. What could I be doing wrong? What might the issue be? Thanks a lot.
Documentation link: https://nestjs-i18n.com/guides/dto_validation/global-validation
login.dto.ts
import { IsEmail, IsNotEmpty } from 'class-validator';
import { i18nValidationMessage } from 'nestjs-i18n';
export class LoginDto {
@IsEmail()
email: string;
@IsNotEmpty({
message: i18nValidationMessage('translation.validation.NOT_EMPTY'),
})
password: string;
}
src/i18n/en/translation.json
"validation": {
"NOT_EMPTY": "{property} value can't be empty "
}
}
src/main.ts
app.useGlobalPipes(
new I18nValidationPipe(),
);
app.useGlobalFilters(new I18nValidationExceptionFilter(), new BadRequestFilter(), new TypeORMExceptionFilter());
Response
{
"status": 401,
"notification": {
"title": "Validation error",
"message": "A problem occurred during the validation of the entered data. Check your data and try again"
},
"details": {
"password": [
"translation.validation.NOT_EMPTY|{\"value\":\"\"}"
]
},
"error": "Unauthorized"
}
To use nestjs-i18n in your DTO validation you first need to follow the nestjs instructions. After that you need to use the I18nValidationPipe.