说明如何使用I18n.l @ user.created_at,format::default [英] Explanation how to use I18n.l @user.created_at, format: :default

查看:106
本文介绍了说明如何使用I18n.l @ user.created_at,format::default的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当翻译日期格式与I18n.l或帮助者'在视图中如下所示:

When translating a date format with I18n.l or the helper ´l´ like this in the view:

l @user.created_at, format: :default

和相应的 sv.yml

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

然后输出是单个字母 m

此问题和出色的解决方案在此记载:奇怪的I18n日期输出与rails ,但我仍然不明白如何输出我的区域的月份。

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.

选择的答案解释说:将上述的月份和日期名称添加到您的YAML中作为数组,您的本地化日期和时间应该开始工作。

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."

有人可以说明这样一个数组应该如何结构化,看起来像吗?

推荐答案

我将以下部分添加到我的yaml文件中:

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将为您提供月份名称,全额
如果要使用缩写的月份名称,可以使用%b,并定义类似的数组称为abbr_month_na您的yaml文件中的mes

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

这篇关于说明如何使用I18n.l @ user.created_at,format::default的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆