Use locales for acceptance macro message

This commit is contained in:
Piotr Solnica 2019-05-04 19:12:59 +02:00
parent 269204ea0a
commit 768edb2c06
No known key found for this signature in database
GPG Key ID: 66BF2FDA7BA0F29C
3 changed files with 8 additions and 1 deletions

4
config/errors.yml Normal file
View File

@ -0,0 +1,4 @@
en:
dry_validation:
errors:
acceptance: "must accept %{key}"

View File

@ -55,6 +55,7 @@ module Dry
extend ClassInterface
config.messages.top_namespace = 'dry_validation'
config.messages.load_paths << Pathname(__FILE__).join('../../../../config/errors.yml').realpath
# @!attribute [r] config
# @return [Config]

View File

@ -9,8 +9,10 @@ module Dry
module RuleMethods
# @api public
def acceptance
key_name = keys[0]
@block = proc do
key.failure('must accept terms') unless values[keys[0]].equal?(true)
key.failure(:acceptance, key: key_name) unless values[key_name].equal?(true)
end
end
end