Class: Dry::Validation::Messages::I18n

Inherits:
Abstract
  • Object
show all
Defined in:
lib/dry/validation/messages/i18n.rb

Constant Summary

Constants inherited from Abstract

Abstract::DEFAULT_PATH

Instance Attribute Summary collapse

Attributes inherited from Abstract

#config

Instance Method Summary collapse

Methods inherited from Abstract

cache, #cache, #call, #lookup, #lookup_paths, #namespaced, #root, #rule

Constructor Details

#initializeI18n

Returns a new instance of I18n.



11
12
13
14
# File 'lib/dry/validation/messages/i18n.rb', line 11

def initialize
  super
  @t = I18n.method(:t)
end

Instance Attribute Details

#tObject (readonly)

Returns the value of attribute t.



7
8
9
# File 'lib/dry/validation/messages/i18n.rb', line 7

def t
  @t
end

Instance Method Details

#get(key, options = {}) ⇒ Object



16
17
18
# File 'lib/dry/validation/messages/i18n.rb', line 16

def get(key, options = {})
  t.(key, options) if key
end

#key?(key, options) ⇒ Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/dry/validation/messages/i18n.rb', line 20

def key?(key, options)
  ::I18n.exists?(key, options.fetch(:locale, I18n.default_locale))
end