【问题标题】:How do I link the same page in another language with the i18n gem for Refinery CMS?如何使用 Refinery CMS 的 i18n gem 链接另一种语言的同一页面?
【发布时间】:2012-07-08 08:24:49
【问题描述】:
我正在将一个网站转换为基于 Rails 的 Refinery CMS,我已经设置了 i18n refinery cms gem,并且我已经创建了我的页面的多语言版本。我想在页面上创建一个语言环境切换器,以便用户可以单击一个标志并在他们所在的特定页面的各种语言之间切换。
如何获取页面的可用语言及其各自的链接?
【问题讨论】:
标签:
ruby-on-rails
ruby-on-rails-3
internationalization
refinerycms
i18n-gem
【解决方案1】:
# In a controller
::I18n.locale = params[:locale]
<!-- In a view with a dropdown -->
<ul id="menu1" class="dropdown-menu" role="menu" aria-labelledby="drop4">
<% Refinery::I18n.frontend_locales.each do |frontend_locale| %>
<li>
<%= link_to Refinery::I18n.locales[frontend_locale], refinery.url_for(:locale => frontend_locale) %>
</li>
<% end %>
</ul>
【解决方案2】:
<ul id="laguages">
<%
@page.translations.each do |t|
%>
<li>
<%= link_to "#{@page.translations.find_by_locale(t.locale).title} (#{Refinery::I18n.locales[t.locale]} #{image_tag("/assets/refinery/icons/flags/#{t.locale}.png")})".html_safe, refinery.url_for(:locale => t.locale) %>
</li>
<%
end
%>
</ul>