| 78 |
if ($n_text =~ /^$pattern$/) { |
if ($n_text =~ /^$pattern$/) { |
| 79 |
$status->{ja}++; |
$status->{ja}++; |
| 80 |
$all_status->{$part}->{ja}++; |
$all_status->{$part}->{ja}++; |
| 81 |
|
my $real_hash = get_hash ($n_text); |
| 82 |
$v = add_class ($tag, 'has-ja-translation', |
$v = add_class ($tag, 'has-ja-translation', |
| 83 |
$pattern{$pattern}->[1]) . |
$pattern{$pattern}->[1], $real_hash) . |
| 84 |
q[<span class=en-original lang=en>] . |
q[<span class=en-original lang=en>] . |
| 85 |
$prefix . |
$prefix . |
| 86 |
escape_id ($text, 'en-') . q[</span>] . |
escape_id ($text, 'en-') . q[</span>] . |
| 88 |
$prefix . |
$prefix . |
| 89 |
replace_pattern2 ($pattern{$pattern}->[0], $1, $2, $3, $4, $5) . |
replace_pattern2 ($pattern{$pattern}->[0], $1, $2, $3, $4, $5) . |
| 90 |
q[</span>]; |
q[</span>]; |
| 91 |
|
|
| 92 |
|
unless ($tbt_added->{$n_text}) { |
| 93 |
|
set_fallback_entry ($real_hash => {en => $text}); |
| 94 |
|
$tbt_added->{$n_text} = 1; |
| 95 |
|
} |
| 96 |
last; |
last; |
| 97 |
} |
} |
| 98 |
} |
} |
| 99 |
|
|
| 100 |
unless (defined $v) { |
unless (defined $v) { |
| 101 |
my $hash = get_hash ($n_text); |
my $hash = get_hash ($n_text); |
| 102 |
$v = add_class ($tag, 'no-ja-translation', $hash) . $prefix . $text; |
$v = add_class ($tag, 'no-ja-translation', $hash) . |
| 103 |
|
'<span class=en-original lang=en>' . |
| 104 |
|
$prefix . $text . |
| 105 |
|
'</span>'; |
| 106 |
|
|
| 107 |
$text =~ s/^\s+//; |
unless ($tbt_added->{$n_text}) { |
|
$text =~ s/\s+\z//; |
|
|
$text =~ s/\x0D?\x0A(?:\x0D?\x0A)+/\n/g; |
|
|
unless ($tbt_added->{$text}) { |
|
| 108 |
set_fallback_entry ($hash => {en => $text}); |
set_fallback_entry ($hash => {en => $text}); |
| 109 |
$tbt_added->{$text} = 1; |
$tbt_added->{$n_text} = 1; |
| 110 |
} |
} |
| 111 |
} |
} |
| 112 |
|
|
| 157 |
|
|
| 158 |
save_fallback_entries (); |
save_fallback_entries (); |
| 159 |
|
|
| 160 |
sub add_class ($$$) { |
sub add_class ($$$;$) { |
| 161 |
my $tag = shift; |
my $tag = shift; |
| 162 |
my $new_class = shift; # should not contain bare & and bare " |
my $new_class = shift; # should not contain bare & and bare " |
| 163 |
my $hash = shift; |
my $hash = shift; |
| 164 |
|
my $real_hash = shift; |
| 165 |
|
$real_hash = qq[ data-ja-real-hash="$real_hash"] if defined $real_hash; |
| 166 |
|
|
| 167 |
if ($tag =~ /^<li\b/) { |
if ($tag =~ /^<li\b/) { |
| 168 |
## NOTE: This |p| wrapper is necessary, otherwise, if |li| element |
## NOTE: This |p| wrapper is necessary, otherwise, if |li| element |
| 169 |
## is set to |display: table|, then no list marker is shown. |
## is set to |display: table|, then no list marker is shown. |
| 170 |
$tag .= qq[<p class="$new_class ja-translation-inserted" data-ja-hash="$hash">]; |
$tag .= qq[<p class="$new_class ja-translation-inserted" data-ja-hash="$hash"$real_hash>]; |
| 171 |
} elsif ($tag =~ /\bclass="/) { |
} elsif ($tag =~ /\bclass="/) { |
| 172 |
$tag =~ s/\bclass="([^"]*)"/class="$1 $new_class" data-ja-hash="$hash"/; |
$tag =~ s/\bclass="([^"]*)"/class="$1 $new_class" data-ja-hash="$hash"$real_hash/; |
| 173 |
} elsif ($tag =~ /\bclass=/) { |
} elsif ($tag =~ /\bclass=/) { |
| 174 |
$tag =~ s/\bclass=([^\s>]+)/class="$1 $new_class" data-ja-hash="$hash"/g; |
$tag =~ s/\bclass=([^\s>]+)/class="$1 $new_class" data-ja-hash="$hash"$real_hash/g; |
| 175 |
} else { |
} else { |
| 176 |
$tag =~ s/>/ class="$new_class" data-ja-hash="$hash">/; |
$tag =~ s/>/ class="$new_class" data-ja-hash="$hash"$real_hash>/; |
| 177 |
} |
} |
| 178 |
|
|
| 179 |
return $tag; |
return $tag; |