5
votes

this is a bit of a beginner's question, but I've searched everywhere and can't seem to solve it.

I'm using Rails and ActiveAdmin, and I've set up internationalization to use my es.yml locale.

So far so good. The admin interface shows up nicely in Spanish, as do error messages, dates, etc. Even the forms pick up the names of the models and the attributes (so formtastic is getting the translations OK). I have only one locale - Spanish:

config/initializers/i18n.rb

#encoding: utf-8
I18n.default_locale = :es

LANGUAGES = [
  [ 'EspaƱol', 'es' ]
]

I have a problem with getting the resource names translated in the ActiveAdmin interface, though. At the top of the page, for example, it says "Users", "Estimates", etc. instead of "Usuarios", "Cotizaciones".

I can solve this by registering the classes like this:

ActiveAdmin.register User, :as => "usuario" do ... end

but then I get admin_usuarios_path, admin_usuarios_url, /admin/usuarios etc. which I find very very ugly. I would rather use English internally. The ActiveAdmin source for active_admin/resource/naming says it should be picking up the model's human_name, which is correctly being read from the localization file:

(in the console)

User.model_name.human.titleize
=> "Usuario" 

So why does "Usuario" not show up on the menu bar, but "User"? I'm a bit mystified here. I must be missing something really simple.

Thanks in advance!

Kyle

2

2 Answers

3
votes

As mentioned in this issue : https://github.com/gregbell/active_admin/issues/434

Your initializer should look like this:

config/initializers/i18n.rb

I18n.load_path += Dir[Rails.root.join('config', 'locales', '*.{rb,yml}').to_s]
I18n.locale = :es
I18n.default_locale = :es
I18n.reload!

Active Admin's support for i18n is not very complete nor stable at present (v0.3.4) but it should get better in the next few releases.

0
votes

There must be something in the controller overriding the default locale. If a locale parameter is set then it becomes the default for the session. You could try clearing your cookies, however somehow the locale was set to another value you can try forcing it to Spanish by adding a GET prarmeter to your URL however other post parameters may override it.

You can set the locale parameter by adding a parameter to the URL. Try something like www.myapp.com/controller/action?locale=es or www.myapp.com/controller/action?parameters_from_active_admin=foo&locale=es

If that dosnt work for you take a look at the Rails console and look at the parameters provided to the application? Is there a locale parameter set to something other than es?

For more information see the Rails i18n guide.