Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option to set locale #2805

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/controllers/rails_admin/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class ApplicationController < Config.parent_controller.constantize
before_action :_authenticate!
before_action :_authorize!
before_action :_audit!
before_action :_set_locale!

helper_method :_current_user, :_get_plugin_name

Expand Down Expand Up @@ -58,6 +59,10 @@ def _audit!
instance_eval(&RailsAdmin::Config.audit_with)
end

def _set_locale!
I18n.locale = RailsAdmin.config.locale if RailsAdmin.config.locale
end

def rails_admin_controller?
true
end
Expand Down
3 changes: 3 additions & 0 deletions lib/rails_admin/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ class << self
# yell about fields that are not marked as accessible
attr_accessor :yell_for_non_accessible_fields

# set locale for rails_admin
attr_accessor :locale

# Setup authentication to be run as a before filter
# This is run inside the controller instance so you can setup any authentication you need to
#
Expand Down
8 changes: 8 additions & 0 deletions spec/controllers/rails_admin/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@
expect(controller.send(:rails_admin_controller?)).to be true
end
end

describe '#_set_locale!' do
it 'works with config' do
RailsAdmin.config.locale = :fr
controller.send(:_set_locale!)
expect(I18n.locale).to eq(:fr)
end
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to clear RailsAdmin.config.locale, otherwise subsequent test cases fail.

end
end