2014-03-30

OTRSの文字化けの直し方1:CSV編 ( CSV Edition: how to fix garbled of OTRS in Japanese )

OTRSのCSV/PDF出力が文字化けしてしまうのを解決する方法
( CSV Edition: how to fix garbled of OTRS in Japanese )

OTRSは非常に使い勝手が良く、様々なことが設定できるなかなかしっかりしたシステムだ。しかし32ヶ国語に翻訳されているなど、世界中で使われているからこそ、日本における環境においてグローバルな対応ではうまくいかないところもある。出力されるファイルの文字コードだ!

OTRSの文字コードは全般的にUTF8を扱っている。そのため出力されるCSVもPDFもUTF8がベースだ。

今回はCSV出力についての文字化け解消方法を紹介致します。

修正方法は以下のとおり。
手順は少なく比較的シンプルです。

以下のコードを追加します。

追加対象ファイル
/Kernel/System/CSV.pm
追加コード(12行目あたり)
use Encode;
追加コード(149行目あたり)
$Output = Encode::encode('shift_jis', decode_utf8($Output));
以下が修正箇所の概要です。
[root@localhost Kernel]# git diff 8185d0c622f80e12412f6ae90989955d3dfba126

diff --git a/Kernel/System/CSV.pm b/Kernel/System/CSV.pm

index 19a15b7..73a7826 100644

--- a/Kernel/System/CSV.pm

+++ b/Kernel/System/CSV.pm

@@ -12,6 +12,7 @@ package Kernel::System::CSV;

 use strict;

 use warnings;

 use Text::CSV;

+use Encode;

 =head1 NAME

@@ -149,6 +150,10 @@ sub Array2CSV {

             );

         }

     }

+

+    # ここでUTF-8 -> SJIS変換を行う

+    $Output = Encode::encode('shift_jis', decode_utf8($Output));

+

     return $Output;

 }