如何将 i18n 用于 Rails 3 中的错误页面? [英] How can I use i18n for my error pages in Rails 3?
问题描述
我需要在我的 public/404.html
页面上使用 I18n api
.
I need use the I18n api
on my public/404.html
page.
如果我添加到 404.html 页面:
If I add to 404.html page:
<%= t('.page_were_looking') %>
我收到如下错误消息:
Cannot use t('.page_were_looking') shortcut because path is not available
如何在此页面上使用 I18n
功能?
How can I use the I18n
feature to this page?
推荐答案
Rails 通过使用类似 public/500.de.html
的路径提供错误页面来支持多语言,其中 de
是语言环境.在 Rails 本身从根本上被破坏的情况下,使用 i18n
是没有意义的.如果 Rails 为获得正确的本地化错误文件而崩溃,那么它或可能服务器将提供 public/500.html
.
Rails supports multilinguality by serving up error pages with a path like public/500.de.html
, where de
is the locale. It makes no sense, to use i18n
for that case when Rails itself is fundamentally broken. If Rails is that much broken to get the right localized error file, it or probably the server will serve public/500.html
.
这是在 Rails 2.3 中引入的.1
This was introduced in Rails 2.3.1
在部署应用程序之前,有一个使用 rake
任务生成此静态文件的解决方案.看看这个要点.
There is the solution to generate this static files with a rake
task, before you deploy the app. Have a look on this gist.
这篇关于如何将 i18n 用于 Rails 3 中的错误页面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!