From 9268d4e11c6cf03285b916c59ecd147579a50424 Mon Sep 17 00:00:00 2001 From: acli Date: Sun, 22 Feb 2004 08:18:27 +0000 Subject: [PATCH] The French character handling fix for tmpl_process3 was not checked in for some reason. Try to remove trailing ( in strings too. --- misc/translator/TmplTokenizer.pm | 51 +++++++++++++++++++++++--------- misc/translator/tmpl_process3.pl | 7 +++++ 2 files changed, 44 insertions(+), 14 deletions(-) diff --git a/misc/translator/TmplTokenizer.pm b/misc/translator/TmplTokenizer.pm index 4b16df05ac..e5177c4765 100644 --- a/misc/translator/TmplTokenizer.pm +++ b/misc/translator/TmplTokenizer.pm @@ -442,6 +442,42 @@ sub _formalize ($) { return $t->type == TmplTokenType::DIRECTIVE? '%s': _quote_cformat($t->string); } +sub _optimize { + my $this = shift; + my @structure = @_; + my $undo_trailing_blanks = sub { + for (my $i = $#structure; $i >= 0; $i -= 1) { + last if $structure[$i]->type != TmplTokenType::TEXT; + last if !blank_p($structure[$i]->string); + push @{$this->{_queue}}, pop @structure; + } + }; + # FIXME: If the last token is a close tag but there are no tags + # FIXME: before it, drop the close tag back into the queue. This + # FIXME: is an ugly hack to get rid of "foo %s" type mess. + if (@structure >= 2 + && $structure[$#structure]->type == TmplTokenType::TAG + && $structure[$#structure]->string =~ /^<\//s) { + my $has_other_tags_p = 0; + printf STDERR "last token %d is type %s: %s\n", $#structure, $structure[$#structure]->type->to_string, $structure[$#structure]->string; + for (my $i = 0; $i < $#structure; $i += 1) { + printf STDERR "token %d is type %s: %s\n", $i, $structure[$i]->type->to_string, $structure[$i]->string; + $has_other_tags_p = 1 if $structure[$i]->type == TmplTokenType::TAG; + last if $has_other_tags_p; + } + push @{$this->{_queue}}, pop @structure unless $has_other_tags_p; + &$undo_trailing_blanks; + } + # FIXME: Do the same ugly hack for the last token being a ( or [ + if (@structure >= 2 + && $structure[$#structure]->type == TmplTokenType::TEXT + && $structure[$#structure]->string =~ /^[\(\[]$/) { # not )] + push @{$this->{_queue}}, pop @structure; + &$undo_trailing_blanks; + } + return @structure; +} + sub next_token { my $this = shift; my $h = $this->_handle; @@ -485,20 +521,7 @@ sub next_token { for (my $i = 0; $i < $n_trailing_spaces; $i += 1) { push @{$this->{_queue}}, pop @structure; } - # FIXME: If the last token is a close tag but there are no tags - # FIXME: before it, drop the close tag back into the queue. This - # FIXME: is an ugly hack to get rid of "foo %s" type mess. - if (@structure >= 2 - && $structure[$#structure]->type == TmplTokenType::TAG - && $structure[$#structure]->string =~ /^<\//) { - my $has_other_tags_p = 0; - for (my $i = 0; $i < $#structure; $i += 1) { - $has_other_tags_p = 1 - if $structure[$i]->type == TmplTokenType::TAG; - last if $has_other_tags_p; - } - push @{$this->{_queue}}, pop @structure unless $has_other_tags_p - } + @structure = $this->_optimize( @structure ); if (@structure < 2) { # Nothing to do ; diff --git a/misc/translator/tmpl_process3.pl b/misc/translator/tmpl_process3.pl index 82cd768803..ae383fea33 100755 --- a/misc/translator/tmpl_process3.pl +++ b/misc/translator/tmpl_process3.pl @@ -33,6 +33,7 @@ use vars qw( $charset_in $charset_out ); sub find_translation ($) { my($s) = @_; my $key = TmplTokenizer::quote_po($s) if $s =~ /\S/; + $key = TmplTokenizer::charset_convert($key, $charset_in, $charset_out); return defined $href->{$key} && !$href->{$key}->fuzzy && length Locale::PO->dequote($href->{$key}->msgstr)? @@ -146,6 +147,9 @@ GetOptions( VerboseWarnings::set_application_name $0; VerboseWarnings::set_pedantic_mode $pedantic_p; +# try to make sure .po files are backed up (see BUGS) +$ENV{VERSION_CONTROL} = 't'; + # keep the buggy Locale::PO quiet if it says stupid things $SIG{__WARN__} = sub { my($s) = @_; @@ -319,6 +323,9 @@ msgmerge(1) command must also be present in the search path. The script currently does not check carefully whether these dependent commands are present. +If xgettext.pl is interrupted by the user, a corrupted po file +will result. This is very seriously wrong. + Locale::PO(3) has a lot of bugs. It can neither parse nor generate GNU PO files properly; a couple of workarounds have been written in TmplTokenizer and more is likely to be needed -- 2.39.5