Search code examples
ruby-on-railsruby-on-rails-3internationalizationrefinerycmsi18n-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. 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?


Solution

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