From 9ef7ab16751e8fb558e8bf6d60551308d3364af1 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 19 May 2020 12:11:37 +0200 Subject: [PATCH] Bug 25501: Pass the encoding to Locale::PO --- misc/translator/LangInstaller.pm | 10 +++++----- misc/translator/po2json | 2 +- misc/translator/tmpl_process3.pl | 2 +- t/LangInstaller.t | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/misc/translator/LangInstaller.pm b/misc/translator/LangInstaller.pm index 79180cc64e..1872e89922 100644 --- a/misc/translator/LangInstaller.pm +++ b/misc/translator/LangInstaller.pm @@ -310,7 +310,7 @@ sub save_po { $po->{''} ||= $default_pref_po_header; # Write .po entries into a file put in Koha standard po directory - Locale::PO->save_file_fromhash( $self->po_filename("-pref.po"), $po ); + Locale::PO->save_file_fromhash( $self->po_filename("-pref.po"), $po, 'utf-8' ); say "Saved in file: ", $self->po_filename("-pref.po") if $self->{verbose}; } @@ -323,7 +323,7 @@ sub get_po_merged_with_en { my $po_current = $self->{po}; # Get po from previous generation - my $po_previous = Locale::PO->load_file_ashash( $self->po_filename("-pref.po") ); + my $po_previous = Locale::PO->load_file_ashash( $self->po_filename("-pref.po"), 'utf-8' ); for my $id ( keys %$po_current ) { my $po = $po_previous->{Locale::PO->quote($id)}; @@ -572,7 +572,7 @@ sub create_installer { # create output file only if there is something to write if ( $po ) { my $po_file = $self->po_filename( $target->{suffix} ); - Locale::PO->save_file_fromhash( $po_file, $po ); + Locale::PO->save_file_fromhash( $po_file, $po, 'utf-8' ); say "Saved in file: ", $po_file if $self->{verbose}; } } @@ -593,7 +593,7 @@ sub update_installer { if ( $po ) { my ( $fh, $po_temp ) = tempfile(); binmode( $fh, ":encoding(UTF-8)" ); - Locale::PO->save_file_fromhash( $po_temp, $po ); + Locale::PO->save_file_fromhash( $po_temp, $po, 'utf-8' ); my $po_file = $self->po_filename( $target->{suffix} ); eval { my $st = system($self->{msgmerge}." ".($self->{verbose}?'':'-q'). @@ -612,7 +612,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, 'utf-8' ); my $dstyml = LoadFile( $srcyml ); diff --git a/misc/translator/po2json b/misc/translator/po2json index 2f534bead3..c73dd711b6 100755 --- a/misc/translator/po2json +++ b/misc/translator/po2json @@ -67,7 +67,7 @@ sub main my $plural_form_count; # get po object stack - my $pos = Locale::PO->load_file_asarray($src) or die "Can't parse po file [$src]."; + my $pos = Locale::PO->load_file_asarray($src, 'utf-8') or die "Can't parse po file [$src]."; foreach my $po (@$pos) diff --git a/misc/translator/tmpl_process3.pl b/misc/translator/tmpl_process3.pl index 7d70726ebd..4f94e09a6a 100755 --- a/misc/translator/tmpl_process3.pl +++ b/misc/translator/tmpl_process3.pl @@ -303,7 +303,7 @@ for my $in_dir ( @in_dirs ) { } # restores the string list from file -$href = Locale::PO->load_file_ashash($str_file); +$href = Locale::PO->load_file_ashash($str_file, 'utf-8'); # guess the charsets. HTML::Templates defaults to iso-8859-1 if (defined $href) { diff --git a/t/LangInstaller.t b/t/LangInstaller.t index 6e122b368e..f621a0f291 100644 --- a/t/LangInstaller.t +++ b/t/LangInstaller.t @@ -50,7 +50,7 @@ EOF . "-o $tempdir/Koha.pot -D $tempdir koha-tmpl/intranet-tmpl/simple.tt"; system($xgettext_cmd); - my $pot = Locale::PO->load_file_asarray("$tempdir/Koha.pot"); + my $pot = Locale::PO->load_file_asarray("$tempdir/Koha.pot", 'utf-8'); my @expected = ( { -- 2.20.1