
I18n.localize: select format date vs. time
Reported by Steve | July 29th, 2009 @ 03:05 PM
At the moment i18n detects the format to use ('date.formats.' vs. 'time.formats'), by checking whether or not an object responds to :sec. Which is O.K.
But passing the usual Rails ActiveSupport::TimeWithZone to I18n.l doesn't give me an opportunity to say whether I want it to be formatted as a date or time, since it'll choose time (TimeWithZone.responds_to(:sec) == true) and and option 'type' does not exist.
This snippet solves the issue:
def localize(locale, object, format = :default, options={})
(...)
type = options[:type] || (object.respond_to?(:sec) ? 'time' : 'date')
if format === Symbol
format = lookup(locale, :"#{type}.formats.#{format}")
end
format = resolve(locale, object, format, options.merge(:raise => true))
(...)
end
Greetings, my friends! (Can your heart stand the shocking fact about I18n without gettext? -- A tribute to Criswell, the famous psychic telling the story about "Plan 9: From Outer Space." - a classic by Ed Wood.)
Comments and changes to this ticket
-
Props1976 December 23rd, 2018 @ 03:04 PM
That is, unfortunately, is advancing in our general public quickly. There ought to be finished direction and mindfulness about the suicide in the public arena to ward off the general population from it. What's more, let them back towards life. Check this essay writer service which will help you in your life.
-
david001 September 13th, 2019 @ 05:51 PM
Get Unlimited hacks Apps with Amazing Ttips&Tricks https://itrickytech.com/
-
frank benson April 2nd, 2020 @ 01:04 PM
Megfelelően, most bármilyen csizmát megvizsgálok, nem feltétlenül főzöm az ajtók elől ruházati Adidas Yeezy Boost 350 V2 Low Top F36980 Sárga Cipő márkaneveket. (FWIW, társam és valójában nagyon szeretem a sajátos Arc azonosító teryxet).
-
mursalin June 27th, 2020 @ 07:46 PM
I found your post interesting to read. I cant wait to see your post soon. Good Luck with the upcoming update.This article is really very interesting and effective. York, North Yorkshire. carpet cleaning Cambridge
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
Internationalization API for Ruby.
This library is used in Ruby on Rails but also suited for use in other contexts.