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

Already on GitHub? Sign in to your account

My locales are overwritten by the active_admin ones #1730

Kulgar opened this Issue Oct 18, 2012 · 9 comments


None yet
4 participants

Kulgar commented Oct 18, 2012

Hi everyone,

Strange thing:
I've created active_admin.fr.yml in my config/locales folder and put my own translations in here. But there are overwritten by the active_admin ones.

I'm sure of that because when I deleted (on my locale machine) the fr.yml inside the active_admin gem folders, my locales were used correctly in my admin panel.

But this doesn't solve anything, because if I don't delete the active admin's fr.yml file, my locales are never taken into account.

Is there any way to fix this?

The same issue happen on my application. I was trying to find a solution. Thank you @Kulgar :)

Kulgar commented Oct 19, 2012

Hahahaha! I solved it!

It's because of this lines in active_admin/lib/active_admin.rb file:

class Railtie < ::Rails::Railtie
     config.after_initialize do
       # Add load paths straight to I18n, so engines and application can overwrite it.
       require 'active_support/i18n'
       I18n.load_path += Dir[File.expand_path('../active_admin/locales/*.yml', __FILE__)]

See... it's in a "config.after_initialize" so it's loaded after the application's initialization, and I presume it's loading active_admin locales after the application locales. I think that's the reason of the overwrite... Am I true? May it be fixed for the future versions of active_admin? Will you want me to perform a pull request?

What I did to solve the problem is the following:

I just added that block of code:

config.after_initialize do
      # Add load paths straight to I18n, so engines and application can overwrite it.
      require 'active_support/i18n'
      I18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]

At the end of my "application.rb" file in my config folder. I'm not sure if the 'require' is... required, but well it fixed the problem, now my locales are really overwritting active_admin's ones.

@Kulgar your solution doesn't work on my application unfortunately. :( ping @pcreux

Kulgar commented Oct 20, 2012

That's weird... Maybe it's also because I have placed my active_admin .yml in /locales/active_admin/locales/fr.yml in my application.

You should try... And when you say it doesn't work, do you have an error message?

May I see your application? :)

@Kulgar : I haven't any error, it's just still in english instead of the french translation I have. I have try with your solution and still the same problem.

Kulgar commented Oct 20, 2012

Ha, that's normal... It means you haven't configured your "locales" in you application.

My problem was that... Texts were in French but! It was the translations from the active_admin's gem that were rendered and not the ones from my application.

So, anyway, you have to pay attention that your application is actually configured to render French translations. I advice you to fully read this guide: http://guides.rubyonrails.org/i18n.html

Especially, check that you have those lines in your application.rb file:

# tell the I18n library where to find your translations
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}')]
# set default locale to something other than :en
config.i18n.default_locale = :fr 

Then you should have French translations. And then you'll have to use my little fix in order to make Active Admin use your locales instead of its'.

But you have to read the guide. I'm not at work right now and I can't help you further but on Monday I'll be able to. Just let me know if you still have some problems.

@Kulgar : Thank you so much ! The backend is now totaly in french ! ❤️


seanlinsley commented Dec 5, 2012

Translations by default are in config/locales, so this would be the proper function to call:

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '*.yml')]

Kulgar commented Dec 5, 2012

Sorry, my bad, I tipped lib instead of "config". You're totally right! I'll edit my post.

@constan4in constan4in referenced this issue Dec 6, 2012


I18n error! #1803

@pcreux pcreux closed this Dec 6, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment