+sub scanhtmlfile {
+ local *IN;
+
+ open(IN, $_[0]) || die $_[0];
+
+ my $copying = 0;
+ my $issubmit = 0;
+ my $text = "";
+ while (my $line = <IN>) {
+ chomp($line);
+
+ while ("" ne $line) {
+ if (!$copying) {
+ if ($line =~ m|<translate>|i) {
+ my $eom = $+[0];
+ if ($` =~ /$submitsearch/) {
+ $issubmit = 1
+ }
+ substr($line, 0, $eom) = "";
+ $copying = 1;
+ } else {
+ $line = "";
+ }
+
+ } else {
+ if ($line =~ m|</translate>|i) {
+ $text .= $`;
+ substr($line, 0, $+[0]) = "";
+
+ $copying = 0;
+ if ($issubmit) {
+ $submit{$text} = 1;
+ $issubmit = 0;
+ }
+ $alllocales{$text} = 1;
+ $htmllocale{$text} = 1;
+ $text = "";
+
+ } else {
+ $text .= $line;
+ $line = "";
+ }
+ }
+ }
+ }
+
+ close(IN);
+}
+
+sub converthtmlfile {
+ local *IN;
+ local *OUT;
+
+ my $file = shift;
+
+ open(IN, $file) || die;
+
+ my $langcode = (split("/", getcwd()))[-1];
+ $file =~ s/_master.html$/_${langcode}.html/;
+
+ open(OUT, ">$file") || die;
+
+ my $copying = 0;
+ my $text = "";
+ while (my $line = <IN>) {
+ chomp($line);
+ if ("" eq $line) {
+ print(OUT "\n");
+ next;
+ }
+
+ while ("" ne $line) {
+ if (!$copying) {
+ if ($line =~ m|<translate>|i) {
+ print(OUT $`);
+ substr($line, 0, $+[0]) = "";
+ $copying = 1;
+ print(OUT "\n") if ("" eq $line);
+
+ } else {
+ print(OUT "${line}\n");
+ $line = "";
+ }
+
+ } else {
+ if ($line =~ m|</translate>|i) {
+ $text .= $`;
+ substr($line, 0, $+[0]) = "";
+ $copying = 0;
+ $alllocales{$text} = 1;
+ $htmllocale{$text} = 1;
+ print(OUT $self{"texts"}{$text});
+ print(OUT "\n") if ("" eq $line);
+ $text = "";
+
+ } else {
+ $text .= $line;
+ $line = "";
+ }
+ }
+ }
+ }
+
+ close(IN);
+ close(OUT);
+}