且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

用Ruby解析意大利日期

更新时间:2023-11-26 23:14:28

我所能提出的是关于同一个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