Skip to the content
sistrall.it
December 18, 2006

Globalyses and symbols for date formats

Hey, this post is vintage content. It dates back more than 19 years ago: it may contain outdated and inaccurate information.

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

Next

Journey in ActiveSupport

December 19, 2006

Newsletter

Inserisci il tuo indirizzo email per iscriverti alla newsletter e ricevere notifiche occasionali di nuove foto e nuovi articoli via email. No spam, I promise. — Powered by MailChimp

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—2026 Silvano Stralla

To the top

This page was built on Mon, 13 Apr 2026 20:20:48 GMT from code version 63992562.