Skip to content

Instantly share code, notes, and snippets.

@Marchino
Created May 3, 2011 22:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Marchino/954356 to your computer and use it in GitHub Desktop.
Save Marchino/954356 to your computer and use it in GitHub Desktop.
Change page locale and translate url
<ul id="choose_language">
<% I18n.available_locales.each do |locale| %>
<li class="<%=locale.to_s%>">
<a href="http://<%=locale==I18n.default_locale ? 'www' : locale.to_s%>.mydomain.dev/pages/change_locale?url=<%=request.path%>" rel="nofollow"><span>en</span></a>
</li>
<% end %>
</ul>
class PagesController < ApplicationController
def change_locale
path = ActionController::Routing::Routes.recognize_path params[:url]
redirect_to path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment