I'm switching to rails and it becomes sometimes a bit strange. After installing a es.yml file I am trying to output a DATETIME column of my database. If I do this:
= l(a.created_at, :format => :short)
It's ok. It prints a nice date in spanish format. But I am confuse about using abbr_month_names in this way. I have tried in a lot of different ways —believe me, I am around four hours with this issue— but I coudn't find a way to output just the month name in short —lets say "OCT.
I had a look on much sites about i18n and date formats, but articles ends always with the :format => :short example and doesn't cares about other ways to display dates (well, someone also explain how to use the :long format...)
A snippet from the German de.yml
locale:
de:
date:
abbr_month_names:
-
- Jan
- Feb
- Mär
You can directly access the locales by Rails' translate function:
I18n.t :abbr_month_names, :scope => :date // returns ['', 'Jan', 'Feb', 'Mär']
Because abbr_month_names
consists of multiple entries (starting with hyphens) it will return an array. For example you could get the current abbreviated month by:
(I18n.t :abbr_month_names, :scope => :date)[Time.now.month]
You can use a.created_at.strftime('%b')
this link shows all possible datetime parts:
http://www.ruby-doc.org/core-1.9.3/Time.html#method-i-strftime
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With