Class | Time |
In: |
lib/rails/localization.rb
|
Parent: | Object |
Acts the same as strftime, but returns a localized version of the formatted date/time string.
# File lib/rails/localization.rb, line 15 15: def localize(format='default') 16: # unabashedly stolen from Globalize which unabashedly stole this snippet from Tadayoshi Funaba's Date class 17: o = '' 18: format = :date_helper_time_formats.l[format.to_s.downcase] if :date_helper_time_formats.l[format.to_s.downcase] 19: format.scan(/%[EO]?.|./o) do |c| 20: cc = c.sub(/^%[EO]?(.)$/o, '%\\1') 21: case cc 22: when '%A'; o << :date_helper_day_names.l[wday] 23: when '%a'; o << :date_helper_abbr_day_names.l[wday] 24: when '%B'; o << :date_helper_month_names.l[mon] 25: when '%b'; o << :date_helper_abbr_month_names.l[mon] 26: #when '%c'; o << :date_helper_time_formats.l[:default] ? :date_helper_date_formats.l[:default] : strftime('%Y-%m-%d') 27: when '%p'; o << if hour < 12 then :date_helper_am.l else :date_helper_pm.l end 28: else; o << c 29: end 30: end 31: strftime(o) 32: end