From e0c0040f37b2d864b4f1fc71cee4f3d42479e27b Mon Sep 17 00:00:00 2001
From: Tomas Cohen Arazi <tomascohen@gmail.com>
Date: Thu, 22 May 2014 08:47:45 -0300
Subject: [PATCH] Bug 12279: Diacritics in system preference editor broken

This patch changes how .pref files are read. Instead of going through
all our global ultra-tweaked C4::Templates->output method, it adds a new
one that takes care of decoding the .pref file data for storing in memory.

This might need to be re-done in the context of 11944, but at least provides
a clean workaround for 3.16.

To test:
- On clean master, install a translation like:
  cd misc/translator ; perl translate install fr-FR
- Go to sysprefs, opac
=> FAIL: descriptions are encoding-broken
- Apply the patch, reload
=> SUCCESS: Everything shows ok

Regards
To+

Sponsored-by: Universidad Nacional de Cordoba

Signed-off-by: Jonathan Druart <jonathan.druart@biblibre.com>
---
 C4/Templates.pm      | 16 ++++++++++++++++
 admin/preferences.pl |  2 +-
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/C4/Templates.pm b/C4/Templates.pm
index 8d13a49..7093cce 100644
--- a/C4/Templates.pm
+++ b/C4/Templates.pm
@@ -5,6 +5,7 @@ use warnings;
 use Carp;
 use CGI;
 use List::MoreUtils qw/any/;
+use Encode qw/decode/;
 
 # Copyright 2009 Chris Cormack and The Koha Dev Team
 #
@@ -134,6 +135,21 @@ sub output {
     return $data;
 }
 
+sub output_prefs {
+
+    my $self = shift;
+    my $vars = shift;
+
+    my $template = $self->{ TEMPLATE };
+    my $data;
+
+    $template->process( $self->filename,
+                        $vars, \$data )
+      || die "Template process failed: ", $template->error();
+
+    return decode('UTF-8',$data);
+}
+
 sub utf8_arrayref {
     my $arrayref = shift;
     foreach my $element (@$arrayref){
diff --git a/admin/preferences.pl b/admin/preferences.pl
index 8bcdb0a..3336045 100755
--- a/admin/preferences.pl
+++ b/admin/preferences.pl
@@ -54,7 +54,7 @@ sub GetTab {
         local_currency => $local_currency, # currency code is used, because we do not know how a given currency is formatted.
     );
 
-    return YAML::Syck::Load( $tab_template->output() );
+    return YAML::Syck::Load( $tab_template->output_prefs() );
 }
 
 sub _get_chunk {
-- 
2.0.0.rc2