使用abbr_month_names(和类似的)与I18n.l() [英] Use of abbr_month_names (and similars) with I18n.l()

查看:222
本文介绍了使用abbr_month_names(和类似的)与I18n.l()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在切换到轨道,有时候有点奇怪。安装es.yml文件后,我试图输出数据库的DATETIME列。如果我这样做:

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)

没关系它以西班牙语格式打印一个漂亮的日期。但是我以这种方式使用 abbr_month_names 感到困惑。我尝试了很多不同的方式 - 相信我,我在这个问题上大约四个小时 - 但是我没有找到一种方法来输出简短的月份名称,说OCT。

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.

我看了很多关于i18n和日期格式的网站,但文章总是以:format =>:简短的例子结束,并不关心其他显示日期的方法(嗯,有人还解释了如何使用:long format ...)

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

推荐答案

德语 de .yml locale:

de:
  date:
    abbr_month_names:
    - 
    - Jan
    - Feb
    - Mär

您可以通过Rails的翻译功能直接访问本地区域:

You can directly access the locales by Rails' translate function:

I18n.t :abbr_month_names, :scope => :date // returns ['', 'Jan', 'Feb', 'Mär']

因为 abbr_month_names 由多个条目组成(starti ng连字符),它将返回一个数组。例如,您可以通过以下方式获取当前的缩写月份:

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]

这篇关于使用abbr_month_names(和类似的)与I18n.l()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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