How to define error messages for base errors in locales?
class Validator < Dry::Validation::Contract
config.messages.default_locale = I18n.default_locale
config.messages.backend = :i18n
config.messages.top_namespace = :validator
schema do
optional(:id).maybe(:integer)
end
rule do
base.failure(:invalid)
end
end
en:
validator:
errors:
invalid: This is. invalid
~:
invalid: This is invalid
"":
invalid: This is invalid
Validator.new.call({})
# => Dry::Validation::MissingMessageError (Message template for :invalid under "" was not found)
Is there any way other than doing something like the below?
base.failure(I18n.t('validator.errors.base.invalid'))
en:
validator:
errors:
base:
invalid: This is invalid