So i'm using I18n Indonesia localize.
I have a id.yml on config/locales.
I want store value of created_at (datetime) to code (string) and Month translation to my locale before save..
self.code = account.created_at.strftime("%d%B%Y").to_s
I'm trying to see that the translation works in Rails Console.
So I tried:
irb(main):003:0> account = Account.last.created_at
←[1m←[36mAccount Load (35.0ms)←[0m ←[1mSELECT "public"."accounts".* FROM "pub
lic"."accounts" ORDER BY "public"."accounts"."id" DESC LIMIT 1←[0m
=> Sat, 16 Mar 2013 10:07:37 UTC +00:00
irb(main):004:0> account.strftime("%d%B%Y").to_s
=> "16March2013"
irb(main):007:0> I18n.default_locale
=> :id
irb(main):008:0> I18n.t account.strftime("%d%B%Y").to_s
=> "translation missing: id.16March2013"
irb(main):006:0> I18n.l account.strftime("%d%B%Y").to_s
#<Class:0x6fc52c8>: Object must be a Date, DateTime or Time object. "16March2013
" given.
How can I localize month value?
Thank's for your help!
I18n.localizeto format and offset to local timezone - i.e.I18n.l(account.created_at, format: :short)you can add your own custom formats besides long and short - see also guides.rubyonrails.org/i18n.html#adding-date-time-formats and see also this id.yml locales file - github.com/svenfuchs/rails-i18n/blob/master/rails/locale/id.yml - house9created_at(datetime) tocode(string) and Month translation to my locale onbefore_save.. - rails_id