问题
When translating a date format with I18n.l or the helper ´l´ like this 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 appearantly solution is documented here: Strange I18n date output with rails, but I still don't understand how to output the months in my locale.
The choosen answer explains "Add the translations (as arrays in your YAML) for the month and day names as above and your localized dates and times should start working."
Could someone please exemplify how such an array should be structured and look like?
回答1:
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
The %B
will give you the month name in full. If you want to use abbreviated month names, you can use %b
, and define a similar array called abbr_month_names
in your YAML file.
来源:https://stackoverflow.com/questions/20837767/explanation-how-to-use-i18n-l-user-created-at-format-default