From 93d6984aede9cfa31dc250c17af3df83db043138 Mon Sep 17 00:00:00 2001 From: Kevin Carnes Date: Mon, 29 Jan 2024 16:30:09 +0100 Subject: [PATCH] Bug 35933: Do not translate text nodes in xsl:attribute and other tags To test: 1. Install another language 2. Notice that MARC21slim2OPACDetail.xsl has translated attributes 3. Apply patch 4. Install the language again 5. Notice that only non-attributes are translated --- C4/TTParser.pm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/C4/TTParser.pm b/C4/TTParser.pm index 7007fb6604..a407034eeb 100644 --- a/C4/TTParser.pm +++ b/C4/TTParser.pm @@ -21,6 +21,7 @@ use base qw(HTML::Parser); use C4::TmplToken; use strict; use warnings; +use List::MoreUtils qw( any ); #seems to be handled post tokenizer ##hash where key is tag we are interested in and the value is a hash of the attributes we want @@ -31,6 +32,9 @@ use warnings; #tokens found so far (used like a stack) my ( @tokens ); +my $do_not_translate; +my @do_not_translate_tags = qw( xsl:attribute ); + #shiftnext token or undef sub next_token{ return shift @tokens; @@ -72,7 +76,7 @@ sub text{ my $self = shift; my $line = shift; my $work = shift; # original text - my $is_cdata = shift; + my $is_cdata = shift || $do_not_translate; while($work){ # if there is a template_toolkit tag if( $work =~ m/\[%.*?%\]/ ){ @@ -144,6 +148,7 @@ sub start{ my $text = shift; #original text my $t = C4::TmplToken->new( $text, C4::TmplTokenType::TAG, $line, $self->{filename}); my %attr; + $do_not_translate += 1 if any { $_ eq $tag } @do_not_translate_tags; # tags seem to be uses in an 'interesting' way elsewhere.. for my $key( %$hash ) { next unless defined $hash->{$key}; @@ -168,6 +173,7 @@ sub end{ # what format should this be in? my $t = C4::TmplToken->new( $text, C4::TmplTokenType::TAG, $line, $self->{filename} ); my %attr; + $do_not_translate -= 1 if any { "/$_" eq $tag } @do_not_translate_tags; # tags seem to be uses in an 'interesting' way elsewhere.. for my $key( %$hash ) { next unless defined $hash->{$key}; -- 2.34.1