Method: I18n::Backend::Base#localize
- Defined in:
- lib/i18n/backend/base.rb
#localize(locale, object, format = :default, options = EMPTY_HASH) ⇒ Object
Acts the same as strftime
, but uses a localized version of the format string. Takes a key from the date/time formats translations as a format argument (e.g., :short
in :'date.formats'
).
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/i18n/backend/base.rb', line 78 def localize(locale, object, format = :default, = EMPTY_HASH) if object.nil? && .include?(:default) return [:default] end raise ArgumentError, "Object must be a Date, DateTime or Time object. #{object.inspect} given." unless object.respond_to?(:strftime) if Symbol === format key = format type = object.respond_to?(:sec) ? 'time' : 'date' = .merge(:raise => true, :object => object, :locale => locale) format = I18n.t(:"#{type}.formats.#{key}", **) end format = translate_localization_format(locale, object, format, ) object.strftime(format) end |