Method: I18n::Backend::Base#localize

Defined in:
lib/i18n/backend/base.rb

#localize(locale, object, format = :default, options = {}) ⇒ 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').

Raises:



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/i18n/backend/base.rb', line 64

def localize(locale, object, format = :default, options = {})
  if object.nil? && options.include?(:default)
    return options[: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'
    options = options.merge(:raise => true, :object => object, :locale => locale)
    format  = I18n.t(:#{type}.formats.#{key}", options)
  end

  format = translate_localization_format(locale, object, format, options)
  object.strftime(format)
end