mquinson / po4a

Maintain the translations of your documentation with ease (PO for anything)
http://po4a.org/
GNU General Public License v2.0
120 stars 58 forks source link

Malformed encoding while writing to file <output> with charset utf-8: Unknown failure #494

Closed rwmjones closed 1 month ago

rwmjones commented 2 months ago

po4a-translate gives this error which is hard to understand when run on a file.

The PO file is this one: https://github.com/libguestfs/guestfs-tools/blob/master/po-docs/ja.po The input file is this one: https://raw.githubusercontent.com/libguestfs/libguestfs-common/master/mlcustomize/customize-synopsis.pod

I don't believe there are any malformed / non-UTF-8 characters in those files, at least nothing that I can see or that iconv cannot parse.

The problem is really that the error message doesn't actually say what is malformed, so I have no further information to go on here.

$ po4a-translate -f pod -M utf-8 -L utf-8 -k 0 -m ../../common/mlcustomize/customize-synopsis.pod   -p ../ja.po   -l customize-synopsis.pod-t -v -d
po4a-translate is deprecated. The unified po4a(1) program is more convenient and
less error prone. Once configured, `po4a --no-update` can be used as a drop-in 
replacement to `po4a-translate`.
po4a::transtractor::process: Read PO file ../ja.po
po4a::transtractor::process: Read document 
               ../../common/mlcustomize/customize-synopsis.pod
po4a::transtractor::process: Call parse()
po4a::transtractor::process: Done parse()
../../common/mlcustomize/customize-synopsis.pod is 100% translated (0 of 0 
strings).
Malformed encoding while writing to file customize-synopsis.pod-t with charset 
utf-8: Unknown failure
rwmjones commented 2 months ago

I think one problem is there may not be any error at all? The use of eval { .. } or do appears to be wrong, it should be:

--- Locale/Po4a/TransTractor.pm.orig    2024-04-12 21:57:05.646411787 +0100
+++ Locale/Po4a/TransTractor.pm 2024-04-12 21:57:55.136864282 +0100
@@ -511,7 +511,8 @@
     map { print $fh $_ } $self->docheader();
     eval {
         map { print $fh $_ } @{ $self->{TT}{doc_out} };
-    } or do {
+    };
+    if ($@) {
         my $error = $@ || 'Unknown failure';
         chomp $error;
         if ( $charset ne 'UTF-8' && $error =~ /^"\\x\{([^"}]*)\}"/ ) {
rwmjones commented 2 months ago

Happens with: perl-interpreter-5.38.2-506.fc40.x86_64 Does not happen with: perl-interpreter-5.32.1-480.el9.x86_64

rwmjones commented 1 month ago

Closed #494 as completed via fe3baba.

Thanks, can confirm this fixes the problem for me.