Configure Rails Admin with i18n
Ruby On Rails Ruby On Rails Admin Configure I18n
By default, its not that easy to configure your application with i18n. If you wish to
support your local language like esp
, np
, hi
, mx
, etc. you need to follow the
steps i tell you.
Configure your routes.rb
Need to configure your routes.rb to encapsulate the controller with locale info
1
2
3
4
5
6
7
8
9
10
11
12
# routes.rb
scope "(:locale)", locale: /en|np/ do
mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
devise_for :users
root 'home#index'
resource :dashboard do
collection do
get :report
end
end
end
Configure locale in each request
Set the locale for each request
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# initialize/rails_admin.rb
RailsAdmin.config do |config|
### Popular gems integration
## == Devise ==
config.authenticate_with do
default_locale = :np
# Set locale per request
I18n.locale = params[:locale] || default_locale
if current_user.blank? || (current_user.has_role?('super_admin') == false)
flash[:error] = 'You are not authorized to access this resource.'
redirect_to '/'
end
end
config.current_user_method(&:current_user)
Copy yml file to your project
copy .rvm/gems/ruby-2.6.3/gems/rails_admin-1.4.2/config/locales/rails_admin.en.yml
or
https://raw.githubusercontent.com/sferik/railsadmin/master/config/locales/railsadmin.en.yml
to /config/locale/rails_admin.np.yml
or rails_admin.[:locale].yml
Convert the file to your locale.
Common Error
You might encounter a msg in view translation missing for np.datetime.distance_in_words.x_days
add the following to the rails_admin.np.yml
file
1
2
3
4
5
np:
datetime:
distance_in_words:
x_days: "%{count} दिन"
about_x_hours: "%{count} घण्टा"
or you can copy this file to config/locale
of nepali translations.
https://gist.github.com/shivabhusal/84b4d9365bc88843c5249aa41ff57688
You might also like
Step To Step Guide To Build A Todo App With React And Redux
Shiva Bhusal (Software Engineer) 10 Min. Read Feb 28, 2020
React Redux TODO Learn Tutorial ES6 Javascript
Read More..
How To Apply For Adding Category To Driving License In Nepal Online
Shiva Bhusal (Software Engineer) 0 Min. Read Feb 16, 2020
Read More..
Ruby Object Model
Shiva Bhusal (Software Engineer) 2 Min. Read Dec 28, 2019
Ruby Ruby Object Model Objects OOP
Read More..
Rails | Avoiding Race Conditions While Updating Particular Field In Db
Shiva Bhusal (Software Engineer) 2 Min. Read Sep 19, 2018
Ruby On Rails Race Condition Update Database PG
Read More..
Configure Rails Admin With I18n
Shiva Bhusal (Software Engineer) 1 Min. Read Aug 8, 2017
Ruby On Rails Ruby On Rails Admin Configure I18n
Read More..