2

I have followed this beautiful site to create internationalization in my site.

However I cannot figure out how to reload a page with a different locale when a user clicks on a language button.

Example: If the user is here:

/es/events/14

when user hits English language reload to

/en/events/14

This is the view:

 %li= link_to "eu", change_locale_path(:locale => "eu")
 %li= link_to "es", change_locale_path(:locale => "es")
 %li= link_to "en", change_locale_path(:locale => "en")
 %li= link_to "fr", change_locale_path(:locale => "fr")

This the method in ApplicationController

def change_locale
 if current_user
   current_user.locale = params[:locale]
   current_user.save
 else
   I18n.locale = params[:locale]
 end
 redirect_to root_url  (this is temporal)
end

What should I have instead of redirect_to root_url to reload the page?

Sergio Nekora
  • 319
  • 1
  • 5
  • 19
  • you may return to previous page, see http://stackoverflow.com/questions/4652084/ruby-on-rails-how-do-you-get-the-previous-url/8801313#8801313 – gayavat Apr 12 '12 at 08:11
  • I tried that before, but as far as I remembered loads the page with the old locale, because the locale is in the url – Sergio Nekora Apr 12 '12 at 08:15
  • try to parse url and change params[:locale], see http://stackoverflow.com/questions/916067/how-do-i-easily-parse-a-url-with-parameters-in-a-rails-test – gayavat Apr 12 '12 at 08:19

1 Answers1

3
- [:ru, :ua, :en].each do |locale|
  %li= link_to locale, params.merge(locale: locale)
jdoe
  • 15,665
  • 2
  • 46
  • 48