3 # -n do not include custom_ scripts
8 $bindir = "$basedir/bin/mozilla";
9 $menufile = "menu.ini";
11 foreach $item (@ARGV) {
16 opendir DIR, "$bindir" or die "$!";
17 @progfiles = grep { /\.pl/; !/(_|^\.)/ } readdir DIR;
19 @customfiles = grep /_/, readdir DIR;
22 # put customized files into @customfiles
23 @customfiles = () if ($arg{n});
26 @menufiles = ($menufile);
28 opendir DIR, "$basedir" or die "$!";
29 @menufiles = grep { /.*?_$menufile$/ } readdir DIR;
31 unshift @menufiles, $menufile;
34 # slurp the translations in
39 foreach $file (@progfiles) {
45 &scanfile("$bindir/$file");
47 # scan custom_{module}.pl or {login}_{module}.pl files
48 foreach $customfile (@customfiles) {
49 if ($customfile =~ /_$file/) {
50 if (-f "$bindir/$customfile") {
51 &scanfile("$bindir/$customfile");
56 # if this is the menu.pl file
57 if ($file eq 'menu.pl') {
58 foreach $item (@menufiles) {
59 &scanmenu("$basedir/$item");
63 if ($file eq 'menunew.pl') {
64 foreach $item (@menufiles) {
65 &scanmenu("$basedir/$item");
71 eval { require 'missing'; };
74 foreach $text (keys %$missing) {
76 unless ($self{texts}{$text}) {
77 $self{texts}{$text} = $missing->{$text};
82 open FH, ">$file" or die "$! : $file";
84 print FH q|$self{texts} = {
87 foreach $key (sort keys %locale) {
88 if ($self{texts}{$key}) {
89 $text = $self{texts}{$key};
97 $keytext =~ s/'/\\'/g;
98 $keytext =~ s/\\$/\\\\/;
100 print FH qq| '$keytext'|
101 . (' ' x (27 - length($keytext)))
102 . qq| => '$text',\n|;
110 foreach $key (sort keys %subrt) {
113 $text =~ s/\\$/\\\\/;
114 print FH qq| '$text'| . (' ' x (27 - length($text))) . qq| => '$text',\n|;
117 foreach $key (sort keys %submit) {
118 $text = ($self{texts}{$key}) ? $self{texts}{$key} : $key;
120 $text =~ s/\\$/\\\\/;
123 $english_sub =~ s/'/\\'/g;
124 $english_sub =~ s/\\$/\\\\/;
125 $english_sub = lc $key;
127 $translated_sub = lc $text;
128 $english_sub =~ s/( |-|,)/_/g;
129 $translated_sub =~ s/( |-|,)/_/g;
130 print FH qq| '$translated_sub'|
131 . (' ' x (27 - length($translated_sub)))
132 . qq| => '$english_sub',\n|;
145 open FH, ">all" or die "$! : all";
147 print FH q|# These are all the texts to build the translations files.
148 # The file has the form of 'english text' => 'foreign text',
149 # you can add the translation in this file or in the 'missing' file
150 # run locales.pl from this directory to rebuild the translation files
155 foreach $key (sort keys %alllocales) {
156 $text = $self{texts}{$key};
161 $text =~ s/\\$/\\\\/;
170 print FH qq| '$key'| . (' ' x (27 - length($key))) . qq| => '$text',\n|;
182 open FH, ">missing" or die "$! : missing";
184 print FH q|# add the missing texts and run locales.pl to rebuild
189 foreach $text (@missing) {
190 print FH qq| '$text'| . (' ' x (27 - length($text))) . qq| => '',\n|;
202 open(FH, "LANGUAGE");
205 $trlanguage = $language[0];
208 $per = sprintf("%.1f", ($count - $notext) / $count * 100);
209 print "\n$trlanguage - ${per}%\n";
215 sub extract_text_between_parenthesis {
216 my ($fh, $line) = @_;
217 my ($inside_string, $pos, $text, $quote_next) = (undef, 0, "", 0);
220 if (length($line) <= $pos) {
222 return ($text, "") unless ($line);
226 my $cur_char = substr($line, $pos, 1);
228 if (!$inside_string) {
229 if ((length($line) >= ($pos + 3)) && (substr($line, $pos, 2)) eq "qq") {
230 $inside_string = substr($line, $pos + 2, 1);
233 } elsif ((length($line) >= ($pos + 2)) &&
234 (substr($line, $pos, 1) eq "q")) {
235 $inside_string = substr($line, $pos + 1, 1);
238 } elsif (($cur_char eq '"') || ($cur_char eq '\'')) {
239 $inside_string = $cur_char;
241 } elsif ($cur_char eq ")") {
242 return ($text, substr($line, $pos + 1));
250 } elsif ($cur_char eq '\\') {
254 } elsif ($cur_char eq $inside_string) {
255 undef($inside_string);
269 return unless (-f "$file");
271 my $fh = new FileHandle;
272 open $fh, "$file" or die "$! : $file";
274 my ($is_submit, $line_no, $sub_line_no) = (0, 0, 0);
279 # is this another file
280 if (/require\s+\W.*\.pl/) {
282 $newfile =~ s/require\s+\W//;
283 $newfile =~ s/\$form->{path}\///;
284 &scanfile("$bindir/$newfile");
289 ($null, $subrt) = split / +/;
299 my ($null, $country) = split /,/;
300 $country =~ s/^ +[\"\']//;
301 $country =~ s/[\"\'].*//;
307 # is it a submit button before $locale->
308 if (/type\s*=\s*submit/i) {
310 if ($` !~ /\$locale->text/) {
312 $sub_line_no = $line_no;
316 my ($found) = /\$locale->text.*?\(/;
321 ($string, $_) = extract_text_between_parenthesis($fh, $postmatch);
324 # if there is no $ in the string record it
325 unless (($string =~ /\$\D.*/) || ("" eq $string)) {
327 # this guarantees one instance of string
328 $locale{$string} = 1;
330 # this one is for all the locales
331 $alllocales{$string} = 1;
333 # is it a submit button before $locale->
335 $submit{$string} = 1;
338 } elsif ($postmatch =~ />/) {
342 # exit loop if there are no more locales on this line
343 ($rc) = ($postmatch =~ /\$locale->text/);
346 s/^.*?\$locale->text.*?\)//;
348 if ( ($postmatch =~ />/)
349 || (!$found && ($sub_line_no != $line_no) && />/)) {
362 my $fh = new FileHandle;
363 open $fh, "$file" or die "$! : $file";
365 my @a = grep /^\[/, <$fh>;
369 grep { s/(\[|\])//g } @a;
371 foreach my $item (@a) {
372 @b = split /--/, $item;
373 foreach $string (@b) {
375 $locale{$string} = 1;
376 $alllocales{$string} = 1;