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");
65 eval { require 'missing'; };
68 foreach $text (keys %$missing) {
70 unless ($self{texts}{$text}) {
71 $self{texts}{$text} = $missing->{$text};
76 open FH, ">$file" or die "$! : $file";
78 print FH q|$self{texts} = {
81 foreach $key (sort keys %locale) {
82 if ($self{texts}{$key}) {
83 $text = $self{texts}{$key};
91 $keytext =~ s/'/\\'/g;
92 $keytext =~ s/\\$/\\\\/;
94 print FH qq| '$keytext'|
95 . (' ' x (27 - length($keytext)))
104 foreach $key (sort keys %subrt) {
107 $text =~ s/\\$/\\\\/;
108 print FH qq| '$text'| . (' ' x (27 - length($text))) . qq| => '$text',\n|;
111 foreach $key (sort keys %submit) {
112 $text = ($self{texts}{$key}) ? $self{texts}{$key} : $key;
114 $text =~ s/\\$/\\\\/;
117 $english_sub =~ s/'/\\'/g;
118 $english_sub =~ s/\\$/\\\\/;
119 $english_sub = lc $key;
121 $translated_sub = lc $text;
122 $english_sub =~ s/( |-|,)/_/g;
123 $translated_sub =~ s/( |-|,)/_/g;
124 print FH qq| '$translated_sub'|
125 . (' ' x (27 - length($translated_sub)))
126 . qq| => '$english_sub',\n|;
139 open FH, ">all" or die "$! : all";
141 print FH q|# These are all the texts to build the translations files.
142 # The file has the form of 'english text' => 'foreign text',
143 # you can add the translation in this file or in the 'missing' file
144 # run locales.pl from this directory to rebuild the translation files
149 foreach $key (sort keys %alllocales) {
150 $text = $self{texts}{$key};
155 $text =~ s/\\$/\\\\/;
164 print FH qq| '$key'| . (' ' x (27 - length($key))) . qq| => '$text',\n|;
176 open FH, ">missing" or die "$! : missing";
178 print FH q|# add the missing texts and run locales.pl to rebuild
183 foreach $text (@missing) {
184 print FH qq| '$text'| . (' ' x (27 - length($text))) . qq| => '',\n|;
196 open(FH, "LANGUAGE");
199 $trlanguage = $language[0];
202 $per = sprintf("%.1f", ($count - $notext) / $count * 100);
203 print "\n$trlanguage - ${per}%\n";
209 sub extract_text_between_parenthesis {
210 my ($fh, $line) = @_;
211 my ($inside_string, $pos, $text, $quote_next) = (undef, 0, "", 0);
214 if (length($line) <= $pos) {
216 return ($text, "") unless ($line);
220 my $cur_char = substr($line, $pos, 1);
222 if (!$inside_string) {
223 if ((length($line) >= ($pos + 3)) && (substr($line, $pos, 2)) eq "qq") {
224 $inside_string = substr($line, $pos + 2, 1);
227 } elsif ((length($line) >= ($pos + 2)) &&
228 (substr($line, $pos, 1) eq "q")) {
229 $inside_string = substr($line, $pos + 1, 1);
232 } elsif (($cur_char eq '"') || ($cur_char eq '\'')) {
233 $inside_string = $cur_char;
235 } elsif ($cur_char eq ")") {
236 return ($text, substr($line, $pos + 1));
244 } elsif ($cur_char eq '\\') {
248 } elsif ($cur_char eq $inside_string) {
249 undef($inside_string);
263 return unless (-f "$file");
265 my $fh = new FileHandle;
266 open $fh, "$file" or die "$! : $file";
268 my ($is_submit, $line_no, $sub_line_no) = (0, 0, 0);
273 # is this another file
274 if (/require\s+\W.*\.pl/) {
276 $newfile =~ s/require\s+\W//;
277 $newfile =~ s/\$form->{path}\///;
278 &scanfile("$bindir/$newfile");
283 ($null, $subrt) = split / +/;
293 my ($null, $country) = split /,/;
294 $country =~ s/^ +[\"\']//;
295 $country =~ s/[\"\'].*//;
301 # is it a submit button before $locale->
302 if (/type\s*=\s*submit/i) {
304 if ($` !~ /\$locale->text/) {
306 $sub_line_no = $line_no;
310 my ($found) = /\$locale->text.*?\(/;
315 ($string, $_) = extract_text_between_parenthesis($fh, $postmatch);
318 # if there is no $ in the string record it
319 unless (($string =~ /\$\D.*/) || ("" eq $string)) {
321 # this guarantees one instance of string
322 $locale{$string} = 1;
324 # this one is for all the locales
325 $alllocales{$string} = 1;
327 # is it a submit button before $locale->
329 $submit{$string} = 1;
332 } elsif ($postmatch =~ />/) {
336 # exit loop if there are no more locales on this line
337 ($rc) = ($postmatch =~ /\$locale->text/);
340 s/^.*?\$locale->text.*?\)//;
342 if ( ($postmatch =~ />/)
343 || (!$found && ($sub_line_no != $line_no) && />/)) {
356 my $fh = new FileHandle;
357 open $fh, "$file" or die "$! : $file";
359 my @a = grep /^\[/, <$fh>;
363 grep { s/(\[|\])//g } @a;
365 foreach my $item (@a) {
366 @b = split /--/, $item;
367 foreach $string (@b) {
369 $locale{$string} = 1;
370 $alllocales{$string} = 1;