2

Is it possible to set a default locale of controller in Rails. Suppose the application supports different language like, fr, nl, en, cn etc and I want to use 'en' as a default language for the Admin Dashboard Controller. Please suggest

Santosh Aryal
  • 1,276
  • 1
  • 18
  • 41

2 Answers2

7

Just use a before_action callback to set the default locale.

class Admin::DashboardController
  before_action :set_default_locale

  # ...

  private
    def set_default_locale
      I18n.default_locale = :en
    end
end
max
  • 96,212
  • 14
  • 104
  • 165
3
before_action :set_locale
def set_locale
    I18n.locale = params[:locale] || I18n.default_locale
end

more details in link and http://guides.rubyonrails.org/i18n.html

Community
  • 1
  • 1