Ruby on Rails:插入不同语言(区域设置)的部分
有一个视图在我的多语言应用程序中调用部分:
<%= render :partial => 'shared/order', :object => @order %>
默认语言是俄语,并且 shared/_order.html.erb 使用 I18n.t
<%= t('.order_type') %>: <b><%= t("order_types.#{order.order_type}") %></b>
<%= t '.date_and_time' %>: <b><%= l(order.date, :format => :long) %>
我想再次渲染相同的部分但在不更改 I18n.locale 变量的情况下使用英语。通过写这样的东西:
<%= render :partial => 'shared/order', :object => @order %>
<%= render :partial => 'shared/order', :object => @order, :locale => 'en' %>
实现这种行为的最佳实践是什么?
There is a view which is calling a partial in my multilingual application:
<%= render :partial => 'shared/order', :object => @order %>
the default language is Russian and shared/_order.html.erb uses I18n.t
<%= t('.order_type') %>: <b><%= t("order_types.#{order.order_type}") %></b>
<%= t '.date_and_time' %>: <b><%= l(order.date, :format => :long) %>
And I want to render just the same partial one more time but in English without changing the I18n.locale variable. By writing something like this:
<%= render :partial => 'shared/order', :object => @order %>
<%= render :partial => 'shared/order', :object => @order, :locale => 'en' %>
What is the best practices to achieve such behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您始终可以使用类似的方法在特定区域设置中运行代码块:
You can always use something like this to run a code block in a certain locale:
嗯嗯。很难回答的问题。我会做以下事情:
然后在局部视图中:
我真的不知道这是否是最好的。我刚刚想到作为解决你的问题的第一个解决方案。
Hmmmmm. Difficult question. I would do the following:
and then in the partial view:
I really do not know whether this is the best. Just crossed my mind as first solution to your problem.