Globalize3 - two translations in one view

ε祈祈猫儿з 提交于 2019-12-11 13:06:41

问题


I use gem globalize3.

I want to get a translation posts in two languages​​, first in English and then in Russian in one index view. And I want to post that is not in English, was located below in Russian after the English posts. My problem is that since I have a default locale :en, and if:

@posts = Post.with_translations(:en)

I get posts in english as I need, if:

@posts_ru = Post.with_translations(:ru)

I get posts in english too..Probably because the default locale English

How I can get @posts in english and then in russian together in one index view? please help me! thanks in advance!


回答1:


You can get all translations like this:

@posts = Post.with_translations

And in your view use it like below:

<% @posts.each do |post| %>

  <%= post.name(:en) %>
  <%= post.name(:ru) %>

<% end %>


来源:https://stackoverflow.com/questions/12142347/globalize3-two-translations-in-one-view

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