Class: Dry::Validation::Message::Localized

Inherits:
Dry::Validation::Message show all
Defined in:
lib/dry/validation/message.rb

Overview

A localized message type

Localized messsages can be translated to other languages at run-time

Instance Method Summary collapse

Constructor Details

This class inherits a constructor from Dry::Validation::Message

Instance Method Details

#evaluate(**opts) ⇒ Object

Evaluate message text using provided locale

Examples:

result.errors[:email].evaluate(locale: :en, full: true)
# "email is invalid"

Parameters:

  • opts (Hash)

Options Hash (**opts):

  • :locale (Symbol)

    Which locale to use

  • :full (Boolean)

    Whether message text should include the key name



49
50
51
52
# File 'lib/dry/validation/message.rb', line 49

def evaluate(**opts)
  evaluated_text, rest = text.(**opts)
  Message.new(evaluated_text, path: path, meta: rest.merge(meta))
end