Activeadmin Resource Names

This is a slightly beginner question, but I searched everywhere and it seems I can’t solve it.

I use Rails and ActiveAdmin, and I configured internationalization to use the es.yml locale.

So far so good. The admin interface is well manifested in Spanish, as well as error messages, dates, etc. Even forms take the names of models and attributes (so that formatting gets translations in order). I have only one language - Spanish:

configurations / initializers / i18n.rb

 #encoding: utf-8 I18n.default_locale = :es LANGUAGES = [ [ 'Español', 'es' ] ] 

I have a problem getting resource names translated into ActiveAdmin interface. For example, at the top of the page is written "Users", "Ratings", etc. Instead of "Usuarios", "Cotizaciones".

I can solve this by registering classes as follows:

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 domestically. The ActiveAdmin source for active_admin/resource/naming says that it should select the human_name model, which is correctly read from the localization file:

(in console)

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

So why is "Usuario" not showing in the menu bar but "User"? I am a little puzzled here. I have to miss something very simple.

Thanks in advance!

Kyle

+4
source share
2 answers

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

Your initializer should look like this:

configurations / 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 support for i18n is currently not complete and stable (v0.3.4), but it should improve in the next few releases.

+3
source

There should be something in the controller that overrides the default locale. If the locale parameter is specified, it becomes the default value for the session. You can try to clear your cookies, but somehow, a different value was set in the locale, which you can try by forcing it into Spanish by adding a GET primer to your URL, however, other message parameters can override it.

You can set the locale parameter by adding the 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 this dosnt works for you, look at the Rails console and see the options provided to the application? Is there a locale parameter for something other than es?

See the Rails i18n guide for more information.

0
source

Source: https://habr.com/ru/post/1385752/


All Articles