From e9874ae7fecba45c59b80508e6f12baa9916e4d3 Mon Sep 17 00:00:00 2001
From: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Date: Wed, 4 Dec 2019 21:51:16 -0300
Subject: [PATCH] Bug 8937: Translation process removes xml prolog

This patch fix the missing xml prolog in translated
files, xml ot TT.

Is fixed teaching C4::TTParse not to ignore <?..?> constructs,
then teaching xgettext.pl to ignore those strings. Net result is
that they are copied in the translated file.

To test:
1) Update & install your preferred language,
(cd misc/translator/; perl translate update xx-YY; perl translate install xx-YY )

2) Compare the first lines (head -2) of:
koha-tmpl/opac-tmpl/bootstrap/en/xslt/compact.xsl
koha-tmpl/opac-tmpl/bootstrap/en/modules/opac-opensearch.tt
koha-tmpl/intranet-tmpl/prog/en/xslt/plainMARC.xsl
and
koha-tmpl/opac-tmpl/bootstrap/xx-YY/xslt/compact.xsl
koha-tmpl/opac-tmpl/bootstrap/xx-YY/modules/opac-opensearch.tt
koha-tmpl/intranet-tmpl/prog/xx-YY/xslt/plainMARC.xsl

Check the missing prolog

3) Install this patch, repeat 1 and 2, now the prolog is present
on translated files.
---
 C4/TTParser.pm              | 10 ++++++++++
 misc/translator/xgettext.pl |  1 +
 2 files changed, 11 insertions(+)

diff --git a/C4/TTParser.pm b/C4/TTParser.pm
index 4c3a4a0..a55eccd 100644
--- a/C4/TTParser.pm
+++ b/C4/TTParser.pm
@@ -60,6 +60,7 @@ sub build_tokens{
     $self->handler(end => "end", "self, line, tag, attr, text"); #signature is end( self, linenumber, tagename, original text )
     $self->handler(declaration => "declaration", "self, line, text, is_cdata"); # declaration
     $self->handler(comment => "comment", "self, line, text, is_cdata"); # comments
+    $self->handler(process => "process", "self, line, text, is_cdata"); # processing statement <?...?>
 #    $self->handler(default => "default", "self, line, text, is_cdata"); # anything else
     $self->marked_sections(1); #treat anything inside CDATA tags as text, should really make it a C4::TmplTokenType::CDATA
     $self->unbroken_text(1); #make contiguous whitespace into a single token (can span multiple lines)
@@ -116,6 +117,15 @@ sub comment {
     push @tokens, $t;  
 }      
 
+sub process {
+    my $self = shift;
+    my $line = shift;
+    my $work = shift; #original text
+    my $is_cdata = shift;
+    my $t = C4::TmplToken->new( $work, ($is_cdata? C4::TmplTokenType::CDATA : C4::TmplTokenType::TEXT), $line, $self->{filename} );
+    push @tokens, $t;
+}
+
 sub default {
     my $self = shift;
     my $line = shift;
diff --git a/misc/translator/xgettext.pl b/misc/translator/xgettext.pl
index 8890d42..889baf6 100755
--- a/misc/translator/xgettext.pl
+++ b/misc/translator/xgettext.pl
@@ -44,6 +44,7 @@ sub string_negligible_p {
 	    || $t =~ /^[A-Za-z]$/		# single letters
             || $t =~ /^(&[a-z]+;|&#\d+;|&#x[0-9a-fA-F]+;|%%|%s|\s|[[:punct:]])*$/ # html entities,placeholder,punct, ...
         || ( $t =~ /^\[\%.*\%\]$/ and $t !~ /\%\].*\[\%/ )    # pure TT entities
+        || $t =~ /^\s*<\?.*\?>/                               # ignore xml prolog
 	)
 }
 
-- 
2.7.4