lib/dry/schema/message_compiler.rb in dry-schema-1.5.1 vs lib/dry/schema/message_compiler.rb in dry-schema-1.5.2

- old
+ new

@@ -27,10 +27,18 @@ DEFAULT_PREDICATE_RESOLVERS = Hash .new(resolve_predicate).update(key?: resolve_key_predicate).freeze EMPTY_OPTS = VisitorOpts.new EMPTY_MESSAGE_SET = MessageSet.new(EMPTY_ARRAY).freeze + FULL_MESSAGE_WHITESPACE = Hash.new(' ').merge( + ja: '', + zh: '', + bn: '', + th: '', + lo: '', + my: '', + ) param :messages option :full, default: -> { false } option :locale, default: -> { :en } @@ -201,25 +209,33 @@ text = template[template.data(tokens)] return text if !text || !full rule = options[:path] - "#{messages.rule(rule, options) || rule} #{text}" + [messages.rule(rule, options) || rule, text].join(FULL_MESSAGE_WHITESPACE[template.options[:locale]]) end # @api private def message_tokens(args) - args.each_with_object({}) do |arg, hash| + tokens = args.each_with_object({}) do |arg, hash| case arg[1] when Array hash[arg[0]] = arg[1].join(LIST_SEPARATOR) when Range hash["#{arg[0]}_left".to_sym] = arg[1].first hash["#{arg[0]}_right".to_sym] = arg[1].last else hash[arg[0]] = arg[1] end end + args.any? { |e| e.first == :size } ? append_mapped_size_tokens(tokens) : tokens + end + + # @api private + def append_mapped_size_tokens(tokens) + # this is a temporary fix for the inconsistency in the "size" errors arguments + mapped_hash = tokens.each_with_object({}) { |(k, v), h| h[k.to_s.gsub("size", "num").to_sym] = v } + tokens.merge(mapped_hash) end end end end