Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV export with localised column headers and inhibiting from import #58

Open
kennym opened this issue Aug 9, 2015 · 3 comments
Open

Comments

@kennym
Copy link
Contributor

kennym commented Aug 9, 2015

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)

@Fivell
Copy link
Member

Fivell commented Aug 9, 2015

@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
Copy link
Member

Fivell commented Aug 9, 2015

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

@n-b
Copy link

n-b commented Oct 17, 2019

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

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

No branches or pull requests

3 participants