Class: Dry::Schema::Messages::I18n
- Defined in:
- lib/dry/schema/messages/i18n.rb
Overview
I18n message backend
Constant Summary
Constants inherited from Abstract
Instance Attribute Summary collapse
- #t ⇒ Object readonly
Attributes inherited from Abstract
Instance Method Summary collapse
- #default_locale ⇒ Object private
-
#get(key, options = {}) ⇒ String
Get a message for the given key and its options.
-
#initialize ⇒ I18n
constructor
private
A new instance of I18n.
-
#key?(key, options) ⇒ Boolean
Check if given key is defined.
-
#merge(path) ⇒ Messages::I18n
Merge messages from an additional path.
Methods inherited from Abstract
cache, #cache, #call, #hash, #lookup, #lookup_paths, #namespaced, #root, #rule
Constructor Details
#initialize ⇒ I18n
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of I18n.
15 16 17 18 |
# File 'lib/dry/schema/messages/i18n.rb', line 15 def initialize super @t = I18n.method(:t) end |
Instance Attribute Details
#t ⇒ Object (readonly)
10 11 12 |
# File 'lib/dry/schema/messages/i18n.rb', line 10 def t @t end |
Instance Method Details
#default_locale ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
55 56 57 |
# File 'lib/dry/schema/messages/i18n.rb', line 55 def default_locale I18n.locale || I18n.default_locale || super end |
#get(key, options = {}) ⇒ String
Get a message for the given key and its options
28 29 30 |
# File 'lib/dry/schema/messages/i18n.rb', line 28 def get(key, = {}) t.(key, ) if key end |
#key?(key, options) ⇒ Boolean
Check if given key is defined
37 38 39 40 |
# File 'lib/dry/schema/messages/i18n.rb', line 37 def key?(key, ) ::I18n.exists?(key, .fetch(:locale, default_locale)) || ::I18n.exists?(key, I18n.default_locale) end |
#merge(path) ⇒ Messages::I18n
Merge messages from an additional path
49 50 51 52 |
# File 'lib/dry/schema/messages/i18n.rb', line 49 def merge(path) ::I18n.load_path << path self end |