Explanation of how to use I18n.l @ user.created_at, format :: default

When translating a date format from I18n.l or the helper 'l' , as shown in the view:

l @user.created_at, format: :default 

and in the corresponding sv.yml :

 sv: time: formats: default: "%B" 

then the output is a single letter m .

This problem and an explicit solution are documented here: Strange I18n date output with rails , but I still don't understand how to display the months in my locale.

The answer selected explains: "Add translations (like arrays in YAML) for the month and day names as above, and your localized dates and times should start working."

Can someone explain how such an array should be structured and look like?

+3
source share
1 answer

I added the following part to my YAML file:

 en: datetime: &datetime month_names: [~, January, February, March, April, May, June, July, August, September, October, November, December] formats: default: "%d/%m/%Y" short: "%d/%m/%Y" day_month: "%d/%m" date: <<: *datetime time: <<: *datetime 

%B will give you the name of the month in full. If you want to use the abbreviated month names, you can use %B and define a similar array named abbr_month_names in your YAML file.

+3
source

All Articles