Method: Confstruct.i18n
- Defined in:
- lib/confstruct/hash_with_struct_access.rb
.i18n(key = nil, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/confstruct/hash_with_struct_access.rb', line 20 def self.i18n key=nil, &block raise NameError, "I18n handler not loaded" unless Object.const_defined? :I18n # ensure the Rails I18n handler is loaded Deferred.new do |hwsa| val = block_given? ? eval_or_yield(hwsa, &block) : key if val.is_a?(Date) or val.is_a?(Time) or val.is_a?(DateTime) ::I18n.localize val else ::I18n.translate val end end end |