From bee8929de69ff480ce9f8d666a3ebb23554028c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Kylm=C3=A4l=C3=A4?= Date: Wed, 5 May 2021 17:20:38 +0300 Subject: [PATCH] Bug 28291: Make koha-translate script produce valid UTF-8 YAML files We had two problems in the LangInstaller.pm module: 1) the PO file was read as bytes instead of as a UTF-8 text stream 2) The YAML file being outputted was double encoded, once by setting the file handle to output UTF-8 and other time in the DumpFile function internally To test: 1. Before applying patch do the following $ cd misc/translator $ ./translate update pl-PL $ ./translate install pl-PL $ cd - $ less installer/data/mysql/pl-PL/marcflavour/marc21/mandatory/authorities_normal_marc21.yml 2. Notice the output of the authorities_normal_marc21.yml contains invalid looking UTF-8 characters 3. $ git clean -d -f # to remove the old translation files 4. Apply patch and repeat the steps and notice the authorities_normal_marc21.yml contains valid looking UTF-8 characters Signed-off-by: Jonathan Druart --- misc/translator/LangInstaller.pm | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm index d15d15a82ce..03e4195f223 100644 --- a/misc/translator/LangInstaller.pm +++ b/misc/translator/LangInstaller.pm @@ -306,7 +306,7 @@ sub translate_yaml { my $po_file = $self->po_filename( $target->{suffix} ); return $srcyml unless ( -e $po_file ); - my $po_ref = Locale::PO->load_file_ashash( $po_file ); + my $po_ref = Locale::PO->load_file_ashash( $po_file, 'utf8' ); my $dstyml = YAML::XS::LoadFile( $srcyml ); @@ -400,9 +400,7 @@ sub install_installer { for my $file ( @files ) { if ( $file =~ /yml$/ ) { my $translated_yaml = translate_yaml( $self, $target, "$intradir/$dir/$file" ); - open(my $fh, ">:encoding(UTF-8)", "$intradir/$tdir/$file"); - YAML::XS::DumpFile( $fh, $translated_yaml ); - close($fh); + YAML::XS::DumpFile( "$intradir/$tdir/$file", $translated_yaml ); } else { File::Copy::copy( "$intradir/$dir/$file", "$intradir/$tdir/$file" ); } -- 2.20.1