【发布时间】:2012-10-19 02:46:46
【问题描述】:
在佛教时代的历法中已经是 2555 年。让 Date.current 显示 2555 而不是 2012 的最简单方法是什么?
更新
我已经找到了这个特定任务的解决方案。只需使用标准 rails i18n 即可轻松实现。
cat config/locales/th.rb
{
th: {
date: {
formats: {
default: lambda { |date, _| "%d.%m.#{date.year + 543}" }
}
}
}
}
然后只使用 I18n.l 方法:
ruby-1.9.3-p194 :032 > I18n.l(Date.current)
=> "30.10.2555"
【问题讨论】:
标签: ruby-on-rails ruby internationalization rails-i18n