Open darshithedpara opened 1 year ago
Because you interpolation syntax is wrong with i18n messages. Check this guide https://docs.adonisjs.com/guides/i18n#interpolation
@thetutlage Do you mean in Validator.json I need to use a single curly brace for referencing dynamic values? I tried that already but it gives me the same error.
It's working for others and not working for enum and enumSet
{
"errors": {
"somethingWentWrong": "Something went wrong.!",
"unauthorizedAccess": "Unauthorized access.!",
"dontHavePermission": "You don't have access to perform this action.!",
"validationFailed": "validation failed.!"
},
"crud": {
"list": "{item} fetched successfully.!",
"show": "{item} fetched successful.!",
"create": "{item} create successful.!",
"update": "{item} update successful.!",
"delete": "{item} deleted successful.!",
"notFound": "{item} not found.!"
}
}
Is anyone else facing the same issue?
Hey @darshithedpara! 👋🏻
It would be easier if you could share a repository with the minimum amount of code to reproduce your issue.
Hello @RomainLanz
You can find the sample code and postman collection here. enum-test-poc.zip Enum Test.postman_collection.zip
I have created 2 validator request, one with i18n json and in another one I have defined the validatgion messages directly to validator class : 1]
2]
@RomainLanz You able to reproduce this issue?
As said per @thetutlage, your interpolation is wrong. ICU messages syntax does not support nested data, so everything is flattened. You can access the property by referencing choices
directly.
Change your i18n message by the following and it should work:
"provider_name.enum": "provider name is not supported - EN { choices }"
@RomainLanz Yes with flattened it is working but it is producing different results.
1] With messages property in validator class : (Here choices are coming as comma-separated string)
2] With i18n JSON : (Here choices are coming as Array of string)
Package version :
Node.js :
9.5.1
npm version :
v18.16.1
Sample Code (to reproduce the issue)
❌ Not Working when we defined custom messages in i18n JSON :
1] Source :
Validator JSON : location for json file :
resources/lang/en/validator.json
1] Source output :
✅ Working when we defined custom messages inside validator class itself :
2] Source :
2] Source output :