Activeadmin: Translation of menu parent

Created on 2 Jun 2014  路  2Comments  路  Source: activeadmin/activeadmin

If you try to use a I18n label for a menu's parent it does not get translated.
For example:

 menu :parent => I18n.t("active_admin.vehicles") , :priority => 2, url: ->{ admin_cars_path(locale: I18n.locale) }

Also you can not use a proc

  Proc isn't supported as a Menu ID

I've found a the same question in issues, but its from 2012 and completely out of sync with the current code.

https://github.com/gregbell/active_admin/issues/1361#issuecomment-6075380

Most helpful comment

This is covered in the menu documentation. Since you want the translation of the parent menu item to be dynamic, your above code doesn't make it possible to tie the child menu item to it. To do that, you have to provide an ID for the parent menu item. For example:

# config/initializers/active_admin.rb
config.namespace :admin do |admin|
  admin.build_menu do |menu|
    menu.add id: 'vehicles', label: proc{ I18n.t 'active_admin.vehicles' }
  end
end

# app/admin/car.rb
ActiveAdmin.register Car do
  menu parent: 'vehicles', priority: 2, url: ->{ admin_cars_path(locale: I18n.locale) }
end

All 2 comments

This is covered in the menu documentation. Since you want the translation of the parent menu item to be dynamic, your above code doesn't make it possible to tie the child menu item to it. To do that, you have to provide an ID for the parent menu item. For example:

# config/initializers/active_admin.rb
config.namespace :admin do |admin|
  admin.build_menu do |menu|
    menu.add id: 'vehicles', label: proc{ I18n.t 'active_admin.vehicles' }
  end
end

# app/admin/car.rb
ActiveAdmin.register Car do
  menu parent: 'vehicles', priority: 2, url: ->{ admin_cars_path(locale: I18n.locale) }
end

I completely missed that in the docs.

Thanks !

Was this page helpful?
0 / 5 - 0 ratings