Pregunta

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?

¿Fue útil?

Solución

- [:ru, :ua, :en].each do |locale|
  %li= link_to locale, params.merge(locale: locale)
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top