3 # -n do not include custom_ scripts
9 $bindir = "$basedir/bin/mozilla";
10 $menufile = "menu.ini";
12 foreach $item (@ARGV) {
17 opendir DIR, "$bindir" or die "$!";
18 @progfiles = grep { /\.pl/; !/(_|^\.)/ } readdir DIR;
20 @customfiles = grep /_/, readdir DIR;
23 # put customized files into @customfiles
24 @customfiles = () if ($arg{n});
27 @menufiles = ($menufile);
29 opendir DIR, "$basedir" or die "$!";
30 @menufiles = grep { /.*?_$menufile$/ } readdir DIR;
32 unshift @menufiles, $menufile;
35 # slurp the translations in
40 # Read HTML templates.
42 @htmltemplates = <../../templates/webpages/*/*_master.html>;
43 foreach $file (@htmltemplates) {
47 foreach $file (@progfiles) {
53 &scanfile("$bindir/$file");
55 # scan custom_{module}.pl or {login}_{module}.pl files
56 foreach $customfile (@customfiles) {
57 if ($customfile =~ /_$file/) {
58 if (-f "$bindir/$customfile") {
59 &scanfile("$bindir/$customfile");
64 # if this is the menu.pl file
65 if ($file eq 'menu.pl') {
66 foreach $item (@menufiles) {
67 &scanmenu("$basedir/$item");
71 if ($file eq 'menunew.pl') {
72 foreach $item (@menufiles) {
73 &scanmenu("$basedir/$item");
79 eval { require 'missing'; };
82 foreach $text (keys %$missing) {
83 if ($locale{$text} || $htmllocale{$text}) {
84 unless ($self{texts}{$text}) {
85 $self{texts}{$text} = $missing->{$text};
90 open FH, ">$file" or die "$! : $file";
92 print FH q|$self{texts} = {
95 foreach $key (sort keys %locale) {
96 if ($self{texts}{$key}) {
97 $text = $self{texts}{$key};
102 $text =~ s/\\$/\\\\/;
105 $keytext =~ s/'/\\'/g;
106 $keytext =~ s/\\$/\\\\/;
108 print FH qq| '$keytext'|
109 . (' ' x (27 - length($keytext)))
110 . qq| => '$text',\n|;
118 foreach $key (sort keys %subrt) {
121 $text =~ s/\\$/\\\\/;
122 print FH qq| '$text'| . (' ' x (27 - length($text))) . qq| => '$text',\n|;
125 foreach $key (sort keys %submit) {
126 $text = ($self{texts}{$key}) ? $self{texts}{$key} : $key;
128 $text =~ s/\\$/\\\\/;
131 $english_sub =~ s/'/\\'/g;
132 $english_sub =~ s/\\$/\\\\/;
133 $english_sub = lc $key;
135 $translated_sub = lc $text;
136 $english_sub =~ s/( |-|,)/_/g;
137 $translated_sub =~ s/( |-|,)/_/g;
138 print FH qq| '$translated_sub'|
139 . (' ' x (27 - length($translated_sub)))
140 . qq| => '$english_sub',\n|;
151 foreach $file (@htmltemplates) {
152 converthtmlfile($file);
157 open FH, ">all" or die "$! : all";
159 print FH q|# These are all the texts to build the translations files.
160 # The file has the form of 'english text' => 'foreign text',
161 # you can add the translation in this file or in the 'missing' file
162 # run locales.pl from this directory to rebuild the translation files
167 foreach $key (sort keys %alllocales) {
168 $text = $self{texts}{$key};
173 $text =~ s/\\$/\\\\/;
182 print FH qq| '$key'| . (' ' x (27 - length($key))) . qq| => '$text',\n|;
194 open FH, ">missing" or die "$! : missing";
196 print FH q|# add the missing texts and run locales.pl to rebuild
201 foreach $text (@missing) {
202 print FH qq| '$text'| . (' ' x (27 - length($text))) . qq| => '',\n|;
214 open(FH, "LANGUAGE");
217 $trlanguage = $language[0];
220 $per = sprintf("%.1f", ($count - $notext) / $count * 100);
221 print "\n$trlanguage - ${per}%\n";
227 sub extract_text_between_parenthesis {
228 my ($fh, $line) = @_;
229 my ($inside_string, $pos, $text, $quote_next) = (undef, 0, "", 0);
232 if (length($line) <= $pos) {
234 return ($text, "") unless ($line);
238 my $cur_char = substr($line, $pos, 1);
240 if (!$inside_string) {
241 if ((length($line) >= ($pos + 3)) && (substr($line, $pos, 2)) eq "qq") {
242 $inside_string = substr($line, $pos + 2, 1);
245 } elsif ((length($line) >= ($pos + 2)) &&
246 (substr($line, $pos, 1) eq "q")) {
247 $inside_string = substr($line, $pos + 1, 1);
250 } elsif (($cur_char eq '"') || ($cur_char eq '\'')) {
251 $inside_string = $cur_char;
253 } elsif ($cur_char eq ")") {
254 return ($text, substr($line, $pos + 1));
262 } elsif ($cur_char eq '\\') {
266 } elsif ($cur_char eq $inside_string) {
267 undef($inside_string);
281 return unless (-f "$file");
283 my $fh = new FileHandle;
284 open $fh, "$file" or die "$! : $file";
286 my ($is_submit, $line_no, $sub_line_no) = (0, 0, 0);
291 # is this another file
292 if (/require\s+\W.*\.pl/) {
294 $newfile =~ s/require\s+\W//;
295 $newfile =~ s/\$form->{path}\///;
296 &scanfile("$bindir/$newfile");
301 ($null, $subrt) = split / +/;
311 my ($null, $country) = split /,/;
312 $country =~ s/^ +[\"\']//;
313 $country =~ s/[\"\'].*//;
319 # is it a submit button before $locale->
320 if (/type\s*=\s*submit/i) {
322 if ($` !~ /\$locale->text/) {
324 $sub_line_no = $line_no;
328 my ($found) = /\$locale->text.*?\(/;
333 ($string, $_) = extract_text_between_parenthesis($fh, $postmatch);
336 # if there is no $ in the string record it
337 unless (($string =~ /\$\D.*/) || ("" eq $string)) {
339 # this guarantees one instance of string
340 $locale{$string} = 1;
342 # this one is for all the locales
343 $alllocales{$string} = 1;
345 # is it a submit button before $locale->
347 $submit{$string} = 1;
350 } elsif ($postmatch =~ />/) {
354 # exit loop if there are no more locales on this line
355 ($rc) = ($postmatch =~ /\$locale->text/);
358 s/^.*?\$locale->text.*?\)//;
360 if ( ($postmatch =~ />/)
361 || (!$found && ($sub_line_no != $line_no) && />/)) {
374 my $fh = new FileHandle;
375 open $fh, "$file" or die "$! : $file";
377 my @a = grep /^\[/, <$fh>;
381 grep { s/(\[|\])//g } @a;
383 foreach my $item (@a) {
384 @b = split /--/, $item;
385 foreach $string (@b) {
387 $locale{$string} = 1;
388 $alllocales{$string} = 1;
397 open(IN, $_[0]) || die;
401 while (my $line = <IN>) {
404 while ("" ne $line) {
406 if ($line =~ m|<translate>|i) {
407 substr($line, 0, $+[0]) = "";
415 if ($line =~ m|</translate>|i) {
417 substr($line, 0, $+[0]) = "";
419 $alllocales{$text} = 1;
420 $htmllocale{$text} = 1;
434 sub converthtmlfile {
438 open(IN, $_[0]) || die;
440 my $langcode = (split("/", getcwd()))[-1];
441 $_[0] =~ s/_master.html$/_${langcode}.html/;
443 open(OUT, ">${_[0]}") || die;
447 while (my $line = <IN>) {
454 while ("" ne $line) {
456 if ($line =~ m|<translate>|i) {
458 substr($line, 0, $+[0]) = "";
460 print(OUT "\n") if ("" eq $line);
463 print(OUT "${line}\n");
468 if ($line =~ m|</translate>|i) {
470 substr($line, 0, $+[0]) = "";
472 $alllocales{$text} = 1;
473 $htmllocale{$text} = 1;
474 print(OUT $self{"texts"}{$text});
475 print(OUT "\n") if ("" eq $line);