localization - How can I make Rails 3 localize my date formats? -
i working on rails 3 project there place date input within form. text field date uses date picker there no concern date being entered in wrong format, date being displayed in :db format (e.g. 2010-01-21).
(note: in form fields - e.g. <%= f.text_field :publish_date %>
, should automatically use :default format, , shouldn't need provided value)
i have tried adding in customized locale has following date configuration:
date: formats: # use strftime parameters formats. # when no format has been given, uses default. # can provide other formats here if like! default: "%d/%m/%y" short: "%b %d" long: "%b %d, %y"
and setting locale (config.i18n.default_locale = "en-au"
) doesn't seem take , becoming quite frustrating.
the app support number of locales, setting initializer override date formats @ application startup isn't suitable, , know should work - i'm guessing i've missed here.
the locale file is: config/locales/en-au.yml
, in application.rb including:
config.i18n.load_path += dir[rails.root.join("config", "locales", "*.yml").to_s] config.i18n.default_locale = "en-au"
in application.rb file.
when displaying date, can use i18n.l
so :
i18n.l @entry.created_at
and if want change it's format :
i18n.l @entry.created_at, :format => :short
the internationalization rails guide documenting that.
Comments
Post a Comment