Rails: how to keep the locale/language parameter across pages

A 1 minute read, Posted by Thomas Brennetot on Thu, Aug 15, 2019
In
Tags rails, i18n, setup

Rails is pretty fantastic to add few lines of code that have a huge impact for multi-language application.

  # app/controllers/application_controller.rb

  # Keep the language parameter if exists
  def default_url_options(_options = {})
    return {} if params[:locale].nil?

    { locale: I18n.locale }
  end