--- test/html-webhacc/cc.cgi 2007/06/30 14:51:10 1.6 +++ test/html-webhacc/cc.cgi 2007/07/01 06:21:46 1.7 @@ -33,6 +33,8 @@ exit; } + load_text_catalog ('en'); ## TODO: conneg + my @nav; print STDOUT qq[Content-Type: text/html; charset=utf-8 @@ -88,13 +90,14 @@ my $onerror = sub { my (%opt) = @_; + my ($cls, $msg) = get_text ($opt{type}, $opt{level}); if ($opt{column} > 0) { - print STDOUT qq[
Line $opt{line} column $opt{column}
\n]; + print STDOUT qq[
Line $opt{line} column $opt{column}
\n]; } else { - $opt{line}--; - print STDOUT qq[
Line $opt{line}
\n]; + $opt{line} = $opt{line} - 1 || 1; + print STDOUT qq[
Line $opt{line}
\n]; } - print STDOUT qq[
@{[htescape $opt{type}]}
\n]; + print STDOUT qq[
$msg
\n]; }; $doc = $dom->create_document; @@ -133,8 +136,7 @@

Parse Errors

-
-]; +
]; push @nav, ['#parse-errors' => 'Parse Error']; my $onerror = sub { @@ -150,8 +152,7 @@ $doc = Message::DOM::XMLParserTemp->parse_byte_stream ($fh => $dom, $onerror, charset => 'utf-8'); - print STDOUT qq[ -
+ print STDOUT qq[
]; } else { @@ -182,15 +183,15 @@

Document Errors

-
-]; +
]; push @nav, ['#document-errors' => 'Document Error']; require Whatpm::ContentChecker; my $onerror = sub { my %opt = @_; - print STDOUT qq[
] . get_node_link ($opt{node}) . - "
\n
", htescape $opt{type}, "
\n"; + my ($cls, $msg) = get_text ($opt{type}, $opt{level}); + print STDOUT qq[
] . get_node_link ($opt{node}) . + qq[
\n
], $msg, "
\n"; }; my $elements; @@ -200,8 +201,7 @@ $elements = Whatpm::ContentChecker->check_document ($doc, $onerror); } - print STDOUT qq[ -
+ print STDOUT qq[
]; @@ -295,12 +295,16 @@ my $s = $_[0]; my $i = 1; print STDOUT qq[
    \n]; - while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { - print STDOUT qq[
  1. ], htescape $1, "
  2. \n"; - $i++; - } - if ($$s =~ /\G([^\x0A]+)/gc) { - print STDOUT qq[
  3. ], htescape $1, "
  4. \n"; + if (length $$s) { + while ($$s =~ /\G([^\x0A]*?)\x0D?\x0A/gc) { + print STDOUT qq[
  5. ], htescape $1, "
  6. \n"; + $i++; + } + if ($$s =~ /\G([^\x0A]+)/gc) { + print STDOUT qq[
  7. ], htescape $1, "
  8. \n"; + } + } else { + print STDOUT q[
  9. ]; } print STDOUT "
"; } # print_input_string @@ -334,7 +338,7 @@ $r .= ''; } - if ($node->has_child_nodes) { + if ($child->has_child_nodes) { $r .= '
    '; unshift @node, @{$child->child_nodes}, '
'; } else { @@ -348,8 +352,12 @@ $r .= qq'
  • <!--' . htescape ($child->data) . '-->
  • '; } elsif ($nt == $child->DOCUMENT_NODE) { $r .= qq'
  • Document'; + $r .= qq[]; if ($child->has_child_nodes) { - $r .= '
      '; + $r .= '
        '; unshift @node, @{$child->child_nodes}, '
      '; } } elsif ($nt == $child->DOCUMENT_TYPE_NODE) { @@ -400,6 +408,40 @@ htescape (get_node_path ($_[0])) . qq[]; } # get_node_link +{ + my $Msg = {}; + +sub load_text_catalog ($) { + my $lang = shift; # MUST be a canonical lang name + open my $file, '<', "cc-msg.$lang.txt" or die "$0: cc-msg.$lang.txt: $!"; + while (<$file>) { + if (s/^([^;]+);([^;]*);//) { + my ($type, $cls, $msg) = ($1, $2, $_); + $msg =~ tr/\x0D\x0A//d; + $Msg->{$type} = [$cls, $msg]; + } + } +} # load_text_catalog + +sub get_text ($) { + my ($type, $level) = @_; + $type = $level . ':' . $type if defined $level; + my @arg; + { + if (defined $Msg->{$type}) { + my $msg = $Msg->{$type}->[1]; + $msg =~ s/\$([0-9]+)/defined $arg[$1] ? htescape ($arg[$1]) : '(undef)'/ge; + return ($Msg->{$type}->[0], $msg); + } elsif ($type =~ s/:([^:]*)$//) { + unshift @arg, $1; + redo; + } + } + return ('', htescape ($_[0])); +} # get_text + +} + =head1 AUTHOR Wakaba . @@ -413,4 +455,4 @@ =cut -## $Date: 2007/06/30 14:51:10 $ +## $Date: 2007/07/01 06:21:46 $