如何解析Ruby on Rails中的翻译日期? [英] How do I parse a translated date in Ruby on Rails?

查看:40
本文介绍了如何解析Ruby on Rails中的翻译日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在Ruby on Rails中配置了一个应用程序,并翻译成西班牙语.

I have configured an application in Ruby on Rails with translations to Spanish.

现在我需要解析翻译日期,例如:

Now I need to parse a translated date, for example:

Jueves,2012年12月22日

Jueves, 22 de Noviembre del 2012

我正在尝试通过这种方式做到这一点:

I'm trying to do it this way:

Date.strptime('Jueves, 22 de Noviembre, 2012', '%A, %e de %B, %Y')

但是会引发无效日期错误.

我该怎么办?

推荐答案

所以,答案是:不可能,至少现在是这样.

So, the answer is: it's not possible, at least right now.

使其工作的唯一方法是在客户端上使用javascript,然后在将字段发送到服务器之前将格式转换为另一种格式.这样,Rails解析就不会有任何问题.

The only way to have it working, is by using javascript on the client side, and convert the format to another one before sending the field to the server. Then Rails will not have any problem parsing it.

这篇关于如何解析Ruby on Rails中的翻译日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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