Skip to content

Commit

Permalink
Try to not fail when writing UTF po files with old Perl versions
Browse files Browse the repository at this point in the history
This is some sort of blind attempt, but I'm rather confident
Fix #495

I still cannot reproduce this bug locally, but Ineiev tracked it down
and tested the patch proposed with Perl v5.16.3 v5.24.1 v5.26.1
v5.26.3 v5.28.1 v5.32.1 v5.34.0 v5.36.0 v5.36.3 v5.38.2. Many thanks
to them about it!

That's a bit sad that it's not part of the v0.72 but duh, that's still
a blind attempt at fixing a problem I cannot reproduce. I'm getting
too old for the last-minute commit breaking the release. I think it
can wait, or maintainers can cherry-pick it if it works for them.
  • Loading branch information
mquinson committed May 25, 2024
1 parent 0274e27 commit ae61c9b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ __ __/ _ \|___ |___ /
\ V /| |_| | / / ___) |
\_/ \___(_)_/ |____/ (not released yet)

General:
* Try to not fail when writing UTF po files with old Perl versions
(GitHub's #495) [Ineiev].

=======================================================================
___ _____ ____
Expand Down
6 changes: 4 additions & 2 deletions lib/Locale/Po4a/Po.pm
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ sub write {
or croak wrap_mod( "po4a::po", dgettext( "po4a", "Cannot write to %s: %s" ), $filename, $! );
}

# Some old perl versions qwak when the encoding is only set to utf. We need to first reset it to raw before setting utf8 again. Not sure why it's so.
binmode( $fh, ':raw' );
binmode( $fh, ':utf8' );
print $fh "" . format_comment( $self->{header_comment}, "" )
if length( $self->{header_comment} );

Expand Down Expand Up @@ -1537,7 +1540,6 @@ sub canonize {
return $text;
}


# Wraps the string. We don't use Text::Wrap since it mangles whitespace at the
# end of the split line.
#
Expand All @@ -1549,7 +1551,7 @@ sub canonize {
# - The extra length allowed for the first line. Default: -10 (which means it
# will be wrapped 10 characters shorter).
sub wrap {
my $text = shift;
my $text = shift;
return "0" if ( $text eq '0' );
my $col = shift || 76;
my $first_shift = shift || -10;
Expand Down

0 comments on commit ae61c9b

Please sign in to comment.