Skip to content

Instantly share code, notes, and snippets.

@yctay
Created October 3, 2012 10:05
Show Gist options
  • Save yctay/3826188 to your computer and use it in GitHub Desktop.
Save yctay/3826188 to your computer and use it in GitHub Desktop.
RefineryCMS frontend locale switcher
<!-- Locale switchers, but presents all available locales as options, even the presently active one -->
<ul>
<% Refinery::I18n.config.frontend_locales.each do |locale| %>
<li>
<%= link_to "/#{locale.to_s + request.path}", {:title => Refinery::I18n.locales[locale]} do%>
<span><%= Refinery::I18n.locales[locale] %></span>
<% end -%>
</li>
<% end %>
</ul>
<!-- Locale switcher that only presents the non-active locale as an option, but requires you to code scenarios -->
<% if I18n.locale.to_s == 'en' %>
<%= link_to 'es'.upcase, refinery.url_for(params.merge(:locale => 'es')) %>
<% else %>
<%= link_to 'en'.upcase, refinery.url_for(params.merge(:locale => 'en')) %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment