Globalize is a plugin that facilitates the internationalisation of applications written in Rails.
The Ruby Mine recently published an introduction to its use.
Globalize provides the localize
method that takes care of correctly formatting the date and time, in tune with the location settings chosen for the application. localize
, unfortunately, is designed to take a date and time formatting string as a parameter; much more convenient would be to be able to use symbols_, as can be done with @tos@ in Rails. Better date.localise(:long)
than date.localise('%d %B %Y %H:%M')
, no?
The following code fragment, added to environment.rb
, allows the desired result to be obtained (involves the use of alias_method_chain
).
module Globalize
module CoreExtensions
module Time
def localize_with_symbol_support(format)
localize_without_symbol_support(::Time::DATE_FORMATS[format] ? ::Time::DATE_FORMATS[format] : format)
end
aliasmethodchain :localize, :symbolsupport end module Date def localizewithsymbolsupport(format) localizewithoutsymbolsupport(::Date::DATEFORMATS[format] ? ::Date::DATEFORMATS[format] : format) end aliasmethodchain :localise, :symbolsupport end end
end
Previous
December 15, 2006
Next
December 19, 2006
I am Silvano Stralla. I am a developer, I like taking photos and riding bikes.
If you want, you can write to me at silvano.stralla at
sistrall.it.
This site is handmade, with love, in Turin (Italy).
© 2002—2024 Silvano Stralla
This page was built on Fri, 06 Sep 2024 10:13:33 GMT from code version 8ba5caf6.