Ruby on Rails I18n-日期的本地化在localhost中有效,但不在生产中 [英] Ruby on Rails I18n - Localization of Dates Works In localhost but Not In Production

查看:84
本文介绍了Ruby on Rails I18n-日期的本地化在localhost中有效,但不在生产中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Ruby on Rails 3.2.13 Ruby 1.9.3.

I am using Ruby on Rails 3.2.13 Ruby 1.9.3.

我的en.yml文件中包含以下代码:

I have the following code in my en.yml file:

date:
  formats:
    default: "%Y-%m-%d"
    short: "%b %d"
    long: "%A, %B %d, %Y"
    mmyy: "%B %Y"

我的fr.yml文件中包含以下代码:

I have the following code in my fr.yml file:

date:
  formats:
    default: "%Y-%m-%d"
    short: "%b %d"
    long: "%A, %d %B %Y"
    mmyy: "%B %Y"

我创建的日期字段media_created以YYYY-MM-DD格式存储在字符串中

My date field media_created is stored in a string in YYYY-MM-DD format

这是我视图中用于在我的视图中显示短日期格式的代码:

Here is the code in my view to display the short date format in my view:

<%= l media_item.media_created.to_date, format: :mmyy %>

以下是我的短格式在localhost(日期为2013-07-01)中如何工作的示例:

Here is an example of how my short format works in localhost (date 2013-07-01):

July 2013 (en)
juillet 2013 (fr)

以下是我的长格式在生产中的工作方式示例(日期为2013-07-01):

Here is an example of how my long format works in production (date 2013-07-01):

July 2013 (en)
July 2013 (fr)

这是我视图中用于在我的视图中显示长日期格式的代码:

Here is the code in my view to display the long date format in my view:

<%= l media_item.media_created.to_date, format: :long %>

以下是我的长格式在localhost(日期为2013-06-23,星期天)中如何工作的示例:

Here is an example of how my long format works in localhost (date 2013-06-23 which was on Sunday):

Sunday, June 23, 2013 (en)
dimanche, 23 juin 2013 (fr)

以下是我的长格式在生产中的工作方式示例(日期为2013-06-23):

Here is an example of how my long format works in production (date 2013-06-23):

Sunday, June 23, 2013 (en)
Sunday, June 23, 2013 (fr)

我阅读了 http://guides.rubyonrails.org/i18n.html 和一些堆栈溢出的示例,如第3.3节所述,该示例使用了l帮助器.但是,在第5节中,它讨论了如何使用t helper进行自定义翻译.我正在将t用于其他所有I18n国际化,并且工作正常.唯一的问题是当我使用l帮助器作为日期时.

I read the http://guides.rubyonrails.org/i18n.html and several examples on Stack Overflow which used the l helper as described in section 3.3. However in section 5 it talks about using the t helper for custom translations. I am using t for all my other I18n internationalization and it is working fine. The only problem is when I use the l helper for dates.

我已经在Rails Guide链接中找到了有关如何使用t helper的示例.该链接未提供有关如何使用字段名称编码语句的示例.我在Stack Overflow中找到的所有示例都使用l helper或strftime方法.我希望能够像在本地主机中一样在生产中处理应用程序的其余部分,从而翻译"日期格式.我已经检查了为在生产服务器上执行此操作而更改的所有文件,以确保所有文件都移到了那里.从我读过的内容来看,l帮助程序似乎不适用于自定义翻译.也许使用t helper可以解决《 Rails指南》建议的问题.我将继续寻找是否可以使用t帮手(例如此处为l帮手提供的示例)找到示例,或者尝试猜测一些解决方案.

I have looked for examples of how to use the t helper as described in the link Rails Guide link. The link does not give an example of how to code a statement with a field name. All of the examples I have found in Stack Overflow are using the l helper or the strftime method. I want to be able to 'translate' the date formats like I do the rest of the application in production like it works in localhost. I have checked all the files that I have changed to do this on my production server to make sure that all the files were moved over there. From what I did read it seems like the l helper may not work that well for custom translations. Maybe using the t helper will take care of this problem which was suggested by the Rails Guide. I will keep looking to see if I can find examples using the t helper like I included here for the l helper or try and guess some solutions.

任何帮助将不胜感激.

更新:2013年7月29日CDT-我在两台服务器之间看到的唯一其他区别是,开发服务器运行的是ruby 1.9.3p327,生产服务器运行的是ruby 1.9.3p362.但是,我不敢相信这可能会导致我的问题,但是我觉得应该注意这是一个不同之处.

UPDATE: 7/29/2013 12:47 pm CDT - The only other difference that I can see between the two servers is that the development server is running ruby 1.9.3p327 and the production server is running ruby 1.9.3p362. However I cannot believe that could be causing my problem but it is a difference that I feel I should note.

推荐答案

我找不到与此有关的任何其他问题或评论.我决定为rails-i18n gem复制fr.yml散列.我不必在开发服务器上执行此操作即可将日期格式转换为法语.正如我所说,没有他们,一切都很好.当我在生产环境中部署新的yaml文件时,我的所有子句都使用法语.我猜想在i18n进程中某个地方的大海捞针类型的错误中有一个问题.至少日期的Rails翻译现在可以正常工作.

I could not find any other questions or comments relating to this. I decided to copy the fr.yml hashes for the rails-i18n gem. I did not have to do this on my development server to get the date formatting to translate into French. As I stated it was working fine without them. When I deployed the new yaml file in production all my clauses are in French. I guess there is a needle in a haystack type of bug somewhere in the i18n process. At least the Rails translations for dates are working now.

这篇关于Ruby on Rails I18n-日期的本地化在localhost中有效,但不在生产中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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