/[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.12 - (hide annotations) (download)
Tue Jul 29 15:12:02 2008 UTC (17 years, 8 months ago) by wakaba
Branch: MAIN
Changes since 1.11: +1 -1 lines
File MIME type: text/plain
*** empty log message ***

1 wakaba 1.1 #!/usr/bin/perl
2     use strict;
3    
4 wakaba 1.11 BEGIN { require 'common.pl' }
5    
6 wakaba 1.6 my $source_file_name = shift;
7     my $result_file_name = shift;
8 wakaba 1.9 my $status_file_name = shift;
9 wakaba 1.1
10     my %data;
11     my %pattern;
12 wakaba 1.11 for_each_data_file (sub ($) {
13     my $data_file_name = shift;
14     warn "$data_file_name...\n";
15     load_data_file ($data_file_name, \%data, \%pattern);
16     });
17 wakaba 1.2 my @pattern = sort {length $b <=> length $a} keys %pattern;
18 wakaba 1.1
19     my $source_text;
20     {
21     warn "$source_file_name...\n";
22     open my $source_file, '<:utf8', $source_file_name
23     or die "$0: $source_file_name: $!";
24     local $/ = undef;
25     $source_text = <$source_file>;
26     }
27    
28 wakaba 1.9 my $status = {};
29    
30 wakaba 1.1 warn "Generating...\n";
31 wakaba 1.12 $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[^>]*)?>).)+)}
32 wakaba 1.1 {
33     my ($tag, $text) = ($1, $2);
34     my $n_text = normalize ($text);
35 wakaba 1.10
36     if (length $n_text) {
37     my $ja_text = $data{$n_text};
38    
39     $status->{all}++;
40    
41     if (defined $ja_text) {
42     $status->{ja}++;
43     $tag . q[<span class=ja-translation lang=ja>] . $ja_text . q[</span>];
44     } else {
45     my $v = $tag . $text;
46     for my $pattern (@pattern) {
47     if ($n_text =~ /^$pattern$/) {
48     $status->{ja}++;
49     $v = $tag . q[<span class=ja-translation lang=ja>] .
50     replace_pattern2 ($pattern{$pattern}, $1, $2, $3, $4, $5) .
51     q[</span>];
52     last;
53     }
54 wakaba 1.1 }
55 wakaba 1.10 $v;
56 wakaba 1.1 }
57 wakaba 1.10 } else {
58     $1 . $2;
59 wakaba 1.1 }
60     }ges;
61     $source_text =~ s{(<(?>link|img|script)\s[^>]+>)}{
62     my $tag = $1;
63     my $n_text = normalize ($tag);
64     my $ja_text = $data{$n_text};
65     if (defined $ja_text) {
66     $ja_text;
67     } else {
68     $tag;
69     }
70     }ges;
71    
72 wakaba 1.4 $source_text =~ s{\[\[([A-Z ]+):([^]]+)\]\]}
73 wakaba 1.1 {<em class=rfc2119 title="$1">$2</em>}gs;
74    
75     #$source_text =~ s[<title>][<base href="http://www.whatwg.org/specs/web-apps/current-work/"><title>];
76    
77     {
78     warn "$result_file_name...\n";
79     open my $result_file, '>:utf8', $result_file_name
80     or die "$0: $result_file_name: $!";
81     print $result_file $source_text;
82 wakaba 1.9 }
83    
84     {
85     my $time = time;
86     open my $status_file, '>>', $status_file_name
87     or die "$0: $status_file_name: $!";
88     print $status_file "$time\t$status->{ja}\t$status->{all}\n";
89 wakaba 1.1 }

admin@suikawiki.org
ViewVC Help
Powered by ViewVC 1.1.24