用Ruby解析意大利日期 [英] Parse Italian Date with Ruby

查看:88
本文介绍了用Ruby解析意大利日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Date.parse,但它不适用于意大利的月份名称!

I would like to use Date.parse, but it doesn't work with Italian month names!



Date.parse26 agosto 1991
=> Sun,26 Jul 2009

Date.parse "26 agosto 1991" => Sun, 26 Jul 2009


有什么办法吗?

推荐答案

我所能提出的是关于同一个schnaader的想法: code> MONTHNAMES 等,然后循环遍历映射,执行 gsub 。那就是:

All I can come up with is about the same schnaader's idea: make a mapping between MONTHNAMES, etc. and then loop through the mapping, doing gsub. That is:

english_to_italian = {
  'english' => 'italian',
  ...
  'august' => 'agosto',
  ...
}

english_to_italian.each do |en, it|
  date_string.gsub!(/\b#{en}\b/i, it)
end

date = Date.parse(date_string)

Date.italy (与日期::意大利​​,我想)方法值得指出,以防万一有日历差异,我不知道。

The Date.italy (same as Date::ITALY, I think) method is worth pointing out, just in case there are calendar differences that I'm not aware of.

真的,我很惊讶,我找不到一个一般的解决方案。也许有一些可以做的Rails的i18n模块?

Really, I'm surprised I couldn't find a general solution for this. Maybe there are some i18n modules for Rails that might do it?

更新:这可能会让你更近,但它看起来不会像所有的一样: http://github.com/rafaelrosafu/i18n_localize_core/tree/master

UPDATE: This might get you closer, but it doesn't look like it would do everything: http://github.com/rafaelrosafu/i18n_localize_core/tree/master

这篇关于用Ruby解析意大利日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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