activescaffoldexportのヘッダのカラム名を日本語にする
Ruby on Railsのプラグインの1つ「activescaffoldexport」で
出力したcsvのヘッダのカラム名は英語になっている。
これを日本語にするには、ヘルパメソッドに次のメソッドを追加すればよい。
(ActiveScaffoldを使用している場合。他の場合はよくわからない)
def format_export_column_header_name(column) column.label end
activescaffoldexportのソースを少し見る
csvのヘッダは以下で生成される。
activescaffoldexport/frontends/default/views/_export.rhtml 8行目
:headers => @export_columns.collect { |column| format_export_column_header_name(column) }
ここで、format_export_column_header_nameを呼び出している。
format_export_column_header_nameの定義は以下である。
activescaffoldexport/lib/helpers/export_helpers.rb 53行目
## This helper can be overridden to change the way that the headers # are formatted. For instance, you might want column.name.to_s.humanize def format_export_column_header_name(column) column.name.to_s end
オーバーライドしてと書いてある。
これをうまいことオーバーライドすることでヘッダを日本語にできる。
ActiveScaffoldでは、column.labelでリストのカラム名等を指定しているので
(active_scaffold/frontends/default/views/_list_column_headings.rhtml 18,27行目)
日記の冒頭のような書き方をするとヘッダを日本語にすることができる。