How can I use i18n for my error pages in Rails 3?

别等时光非礼了梦想. 提交于 2019-12-08 16:55:02

问题


I need use the I18n api on my public/404.html page.

If I add to 404.html page:

<%= t('.page_were_looking') %>

I get an error message like:

Cannot use t('.page_were_looking') shortcut because path is not available

How can I use the I18n feature to this page?


回答1:


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.

This was introduced in Rails 2.3.1

There is the solution to generate this static files with a rake task, before you deploy the app. Have a look on this gist.



来源:https://stackoverflow.com/questions/13308762/how-can-i-use-i18n-for-my-error-pages-in-rails-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!