/[suikacvs]/markup/html/html5/spec-ja/make.pl
Suika

Contents of /markup/html/html5/spec-ja/make.pl

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.13 - (show annotations) (download)
Sun Aug 10 04:16:33 2008 UTC (17 years, 8 months ago) by wakaba
Branch: MAIN
Changes since 1.12: +14 -0 lines
File MIME type: text/plain
*** empty log message ***

1 #!/usr/bin/perl
2 use strict;
3
4 BEGIN { require 'common.pl' }
5
6 my $source_file_name = shift;
7 my $result_file_name = shift;
8 my $status_file_name = shift;
9 my $tbt_file_name = shift;
10
11 my %data;
12 my %pattern;
13 for_each_data_file (sub ($) {
14 my $data_file_name = shift;
15 warn "$data_file_name...\n";
16 load_data_file ($data_file_name, \%data, \%pattern);
17 });
18 my @pattern = sort {length $b <=> length $a} keys %pattern;
19
20 my $source_text;
21 {
22 warn "$source_file_name...\n";
23 open my $source_file, '<:utf8', $source_file_name
24 or die "$0: $source_file_name: $!";
25 local $/ = undef;
26 $source_text = <$source_file>;
27 }
28
29 open my $tbt_file, '>:utf8', $tbt_file_name or die "$0: $tbt_file_name: $!";
30
31 my $status = {};
32
33 warn "Generating...\n";
34 $source_text =~ s{(<(?>p(?>re)?|li|d[td]|t[dh]|h[1-6])(?>\s[^>]*)?>)((?>(?!</?(?>p(?>re)?|li|d(?>[tdl]|iv)|t(?>[dr]|h(?>ead)?|able|body|foot)|h[1-6r]|ul|ol)(?>\s[^>]*)?>).)+)}
35 {
36 my ($tag, $text) = ($1, $2);
37 my $n_text = normalize ($text);
38
39 if (length $n_text) {
40 my $ja_text = $data{$n_text};
41
42 $status->{all}++;
43
44 if (defined $ja_text) {
45 $status->{ja}++;
46 $tag . q[<span class=ja-translation lang=ja>] . $ja_text . q[</span>];
47 } else {
48 my $v = $tag . $text;
49 my $has_ja;
50 for my $pattern (@pattern) {
51 if ($n_text =~ /^$pattern$/) {
52 $status->{ja}++;
53 $v = $tag . q[<span class=ja-translation lang=ja>] .
54 replace_pattern2 ($pattern{$pattern}, $1, $2, $3, $4, $5) .
55 q[</span>];
56 $has_ja = 1;
57 last;
58 }
59 }
60
61 unless ($has_ja) {
62 $text =~ s/^\s+//;
63 $text =~ s/\s+\z//;
64 $text =~ s/\x0D?\x0A(?:\x0D?\x0A)+/\n/g;
65 print $tbt_file $text;
66 print $tbt_file "\n\n";
67 }
68
69 $v;
70 }
71 } else {
72 $1 . $2;
73 }
74 }ges;
75 $source_text =~ s{(<(?>link|img|script)\s[^>]+>)}{
76 my $tag = $1;
77 my $n_text = normalize ($tag);
78 my $ja_text = $data{$n_text};
79 if (defined $ja_text) {
80 $ja_text;
81 } else {
82 $tag;
83 }
84 }ges;
85
86 $source_text =~ s{\[\[([A-Z ]+):([^]]+)\]\]}
87 {<em class=rfc2119 title="$1">$2</em>}gs;
88
89 #$source_text =~ s[<title>][<base href="http://www.whatwg.org/specs/web-apps/current-work/"><title>];
90
91 {
92 warn "$result_file_name...\n";
93 open my $result_file, '>:utf8', $result_file_name
94 or die "$0: $result_file_name: $!";
95 print $result_file $source_text;
96 }
97
98 {
99 my $time = time;
100 open my $status_file, '>>', $status_file_name
101 or die "$0: $status_file_name: $!";
102 print $status_file "$time\t$status->{ja}\t$status->{all}\n";
103 }

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24