Activeadmin + internationalization

I updated active_admin to version 0.3.0 to get internationalization. But I have problems with that.

I have a pl.yml file updated with the activeadmin section that looks like this:

pl: active_admin: blank_slate: content: "Nie ma jeszcze rekordów." link: "Nowy" dashboard: "Dashboard2" view: "Podgląd" 

This did not work, so I tried to add this code to my .rb application:

  config.before_configuration do I18n.locale = :pl I18n.load_path += Dir[Rails.root.join('config', 'locales', '*', '.{rb,yml}')] I18n.reload! end 

Now internationalization seems to work in a development environment, but I still have problems in other environments. I have a problem with the panel: key. Usually, in short, when I18n does not find the key, it puts the key: with a capital letter, in this example it will be "Dashboard". But in my case, I have something like this:

Development:
Development

Production:
Production

Does anyone have the same problem? Am I doing something wrong or is it an activeadmin error? Any solution?

+7
source share
4 answers

I had the same problem. I needed to do this in order to make it work both in production and in development:

 config.before_configuration do I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s] I18n.locale = :nl I18n.default_locale = :nl config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s] config.i18n.locale = :nl # bypasses rails bug with i18n in production\ I18n.reload! config.i18n.reload! end config.i18n.locale = :nl config.i18n.default_locale = :nl 

Not very pretty, but probably caused by a bug in Rails.

+8
source

in application.rb

 config.i18n.default_locale = :fr I18n.locale = config.i18n.locale = config.i18n.default_locale I18n.reload! 
+4
source

The main reason could be caused by: Rails chose the locale from the enduser browser, but not your configuration file. for example, a Japanese will visit your site with its browser using English, then your Rails application will show it the "English" text, but not the Japanese that you want to display it.

According to the Rails i18n document: http://guides.rubyonrails.org/i18n.html , you must first of all:

  • modify config / application.rb to set default_locale

     config.i18n.default_locale = :cn 
  • edit application / controllers / application_controller.rb to add before_filter file

     before_filter :set_locale # for those user whose browser is not using our default_locale, eg a Chinese using English broser, # just like me. :) def set_locale I18n.locale = params[:local] || I18n.default_locale end 
  • in this case you should have "cn" as the default locale.

  • Check your browse page by adding this line of code to any of your pages. eg

     # in products/index.html.erb <h1>Products List</h1> default_locale is: <%= I18n.default_locale %> <br/> current_locale is: <%= I18n.locale %> 
  • the output should look like this:

     Products List default_locale is: cn current_locale is: cn 

    and your Rails application should work as you expect.

+2
source

An alternative that seems to work is to create an initializer with the following:

 # config/initializers/i18n_reload.rb Rails.configuration.after_initialize do I18n.reload! end 
+2
source

All Articles