Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 3.2.11: RailsAdmin localization

I've installed rails_admin gem on my localized site (2 languages) and i need administration (/admin) to be always in English. According to documentation I should add following 2 lines to beginning of rails_admin.rb file.

require 'i18n'
I18n.default_locale = :de

But it's not working. Any idea how to do that?

like image 786
Zeck Avatar asked Oct 05 '22 08:10

Zeck


2 Answers

Stumbled over the same Issue. Here is how I solved it:

class ApplicationController < ActionController::Base
  include Clearance::Controller
  # Prevent CSRF attacks by raising an exception.
  # For APIs, you may want to use :null_session instead.
  protect_from_forgery with: :exception

  before_filter :set_locale

  def set_locale
    if [Clearance, RailsAdmin].include?(self.class.parent)
      I18n.locale = :en
    else
      I18n.locale = params[:locale] || I18n.default_locale
    end
  end
end

RailsAdmin controllers are inheriting form your ApplicationController so you need to tell them explicitly to use the locale :en there or you can open the classes and overwrite set_locale.

like image 195
jethroo Avatar answered Oct 07 '22 23:10

jethroo


It does state on the documentation that you only need to do this if your local is set to something other then English so you may find that you do not need to set this. If you do need to set this then make sure it is below the RailsAdmin.config do |config| line in rails_admin.rb

Update -

As you are still running into problems could you please let me know what version of ruby you are using? Have you run a bundle install? Could you try sudo gem install i18n. Also if it cannot find your locales you may need to point it at them i.e I18n.load_translations "#{RAILS_ROOT}/locales/#{locale}.rb"

like image 31
Jesse Whitham Avatar answered Oct 07 '22 21:10

Jesse Whitham