
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/
-
Walaim Henry March 19th, 2023 @ 04:27 PM
Organizing your refrigerator is a simple and easy task that can make a huge difference in how your food is stored and how quickly you can find what you need. Follow these tips and tricks to keep your refrigerator organized and maximize its storage space. https://refrigeratorshouse.com/best-apartment-size-refrigerator/
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.