active_admin_import icon indicating copy to clipboard operation
active_admin_import copied to clipboard

CSV export with localised column headers and inhibiting from import

Open kennym opened this issue 10 years ago • 3 comments

When exporting data via CSV from the active_admin admin and your environment locale is set to something other than English, like this in an initializer:

I18n.default_locale = :es

The column headers of the exported CSV are in the localised language. When you then try to import that CSV with active_admin_import you'll get an error because it cannot match the headers with the column names which are in English.

I am on master (95fdfe1)

kennym avatar Aug 09 '15 20:08 kennym

@kennym, for now there is no automatic resolving of column names from different locales, but there is workaround. You can change header names from files with header_rewrites option, pls take a look on spec https://github.com/activeadmin-plugins/active_admin_import/blob/master/spec/import_spec.rb#L103

and

https://github.com/activeadmin-plugins/active_admin_import/blob/master/spec/import_spec.rb#L350

Fivell avatar Aug 09 '15 20:08 Fivell

however it can be possible to detect I18n.default_locale and find native column names, do you have ideas how to implement this?

Fivell avatar Aug 09 '15 20:08 Fivell

This is an old topic, but here goes. Say we’re importing an Author model:

header_rewrites = Author.column_names.map { |a| [Author.human_attribute_name(a), a] }.to_h
active_admin_import header_rewrites: header_rewrites

n-b avatar Oct 17 '19 13:10 n-b