简体   繁体   English

如何将另一种语言的同一页面与Refinery CMS的i18n gem链接?

[英]How do I link the same page in another language with the i18n gem for Refinery CMS?

I'm converting a site into the Rails based Refinery CMS, I've setup the i18n refinery cms gem and I've created multi-lingual versions of my pages. 我正在将一个站点转换为基于Rails的Refinery CMS,我已经设置了i18n refinery cms gem,并且我创建了多语言版本的页面。 I'd like to create a locale switcher on the page, so that a user can click on a flag and switch between the various languages for the particular page that they are on. 我想在页面上创建一个区域设置切换器,以便用户可以单击一个标志并在它们所在的特定页面的各种语言之间切换。

How can I get the available languages for a page, and their respective links? 如何获取页面的可用语言及其各自的链接?

# 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>
<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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM