Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 38105908

Von Moritz Bunkus vor etwa 19 Jahren hinzugefügt

  • ID 3810590867a59bab1a4b65d9b4ae67b19038fd19
  • Vorgänger 38087e58
  • Nachfolger e848dbf1

Perltidy ueber locales.pl laufen lassen. Den Parser in locaes.pl so erweitert, dass er auch $text->locale(...)-Funktionsaufrufe auswertet, die ueber mehrere Zeilen gehen. Das wurde durch die Verwendung von perltidy akut, das bei sehr langen Zeilen das Argument zu $text->locale() in eine eigene Zeile schreibt. Einige der dadurch neu/wieder gefundenen Ausdruecke uebersetzt bzw. deren urspruengliche Uebersetzung wiederhergestellt. Merge von 570:573 aus unstable.

Unterschiede anzeigen:

locale/de/locales.pl
4 4

  
5 5
use FileHandle;
6 6

  
7

  
8
$basedir = "../..";
9
$bindir = "$basedir/bin/mozilla";
7
$basedir  = "../..";
8
$bindir   = "$basedir/bin/mozilla";
10 9
$menufile = "menu.ini";
11 10

  
12 11
foreach $item (@ARGV) {
......
32 31
  unshift @menufiles, $menufile;
33 32
}
34 33

  
35

  
36 34
# slurp the translations in
37 35
if (-f 'all') {
38 36
  require "all";
39 37
}
40 38

  
41

  
42 39
foreach $file (@progfiles) {
43
  
40

  
44 41
  %locale = ();
45 42
  %submit = ();
46
  %subrt = ();
47
  
43
  %subrt  = ();
44

  
48 45
  &scanfile("$bindir/$file");
49 46

  
50 47
  # scan custom_{module}.pl or {login}_{module}.pl files
51 48
  foreach $customfile (@customfiles) {
52 49
    if ($customfile =~ /_$file/) {
53 50
      if (-f "$bindir/$customfile") {
54
	&scanfile("$bindir/$customfile");
51
        &scanfile("$bindir/$customfile");
55 52
      }
56 53
    }
57 54
  }
58
  
55

  
59 56
  # if this is the menu.pl file
60 57
  if ($file eq 'menu.pl') {
61 58
    foreach $item (@menufiles) {
......
65 62
  
66 63
  $file =~ s/\.pl//;
67 64

  
68

  
69 65
  eval { require 'missing'; };
70 66
  unlink 'missing';
71 67

  
72 68
  foreach $text (keys %$missing) {
73 69
    if ($locale{$text}) {
74 70
      unless ($self{texts}{$text}) {
75
	$self{texts}{$text} = $missing->{$text};
71
        $self{texts}{$text} = $missing->{$text};
76 72
      }
77 73
    }
78 74
  }
79 75

  
80

  
81 76
  open FH, ">$file" or die "$! : $file";
82 77

  
83 78
  print FH q|$self{texts} = {
......
95 90
    $keytext = $key;
96 91
    $keytext =~ s/'/\\'/g;
97 92
    $keytext =~ s/\\$/\\\\/;
98
    
99
    print FH qq|  '$keytext'|.(' ' x (27-length($keytext))).qq| => '$text',\n|;
93

  
94
    print FH qq|  '$keytext'|
95
      . (' ' x (27 - length($keytext)))
96
      . qq| => '$text',\n|;
100 97
  }
101 98

  
102 99
  print FH q|};
103 100

  
104 101
$self{subs} = {
105 102
|;
106
  
103

  
107 104
  foreach $key (sort keys %subrt) {
108 105
    $text = $key;
109 106
    $text =~ s/'/\\'/g;
110 107
    $text =~ s/\\$/\\\\/;
111
    print FH qq|  '$text'|.(' ' x (27-length($text))).qq| => '$text',\n|;
108
    print FH qq|  '$text'| . (' ' x (27 - length($text))) . qq| => '$text',\n|;
112 109
  }
113 110

  
114 111
  foreach $key (sort keys %submit) {
......
120 117
    $english_sub =~ s/'/\\'/g;
121 118
    $english_sub =~ s/\\$/\\\\/;
122 119
    $english_sub = lc $key;
123
    
120

  
124 121
    $translated_sub = lc $text;
125
    $english_sub =~ s/( |-|,)/_/g;
122
    $english_sub    =~ s/( |-|,)/_/g;
126 123
    $translated_sub =~ s/( |-|,)/_/g;
127
    print FH qq|  '$translated_sub'|.(' ' x (27-length($translated_sub))).qq| => '$english_sub',\n|;
124
    print FH qq|  '$translated_sub'|
125
      . (' ' x (27 - length($translated_sub)))
126
      . qq| => '$english_sub',\n|;
128 127
  }
129
  
128

  
130 129
  print FH q|};
131 130

  
132 131
1;
......
135 134
  close FH;
136 135
}
137 136

  
138

  
139 137
# now print out all
140 138

  
141 139
open FH, ">all" or die "$! : all";
......
148 146
$self{texts} = {
149 147
|;
150 148

  
151

  
152 149
foreach $key (sort keys %alllocales) {
153 150
  $text = $self{texts}{$key};
154 151

  
155 152
  $count++;
156
  
153

  
157 154
  $text =~ s/'/\\'/g;
158 155
  $text =~ s/\\$/\\\\/;
159
  $key =~ s/'/\\'/g;
160
  $key =~ s/\\$/\\\\/;
156
  $key  =~ s/'/\\'/g;
157
  $key  =~ s/\\$/\\\\/;
161 158

  
162 159
  unless ($text) {
163 160
    $notext++;
164 161
    push @missing, $key;
165 162
  }
166 163

  
167
  print FH qq|  '$key'|.(' ' x (27-length($key))).qq| => '$text',\n|;
164
  print FH qq|  '$key'| . (' ' x (27 - length($key))) . qq| => '$text',\n|;
168 165

  
169 166
}
170 167

  
......
175 172

  
176 173
close FH;
177 174

  
178

  
179 175
if (@missing) {
180 176
  open FH, ">missing" or die "$! : missing";
181 177

  
......
185 181
|;
186 182

  
187 183
  foreach $text (@missing) {
188
    print FH qq|  '$text'|.(' ' x (27-length($text))).qq| => '',\n|;
184
    print FH qq|  '$text'| . (' ' x (27 - length($text))) . qq| => '',\n|;
189 185
  }
190 186

  
191 187
  print FH q|};
......
194 190
|;
195 191

  
196 192
  close FH;
197
  
193

  
198 194
}
199 195

  
200 196
open(FH, "LANGUAGE");
......
207 203
print "\n$trlanguage - ${per}%\n";
208 204

  
209 205
exit;
206

  
210 207
# eom
211 208

  
209
sub extract_text_between_parenthesis {
210
  my ($fh, $line) = @_;
211
  my ($inside_string, $pos, $text, $quote_next) = (undef, 0, "", 0);
212

  
213
  while (1) {
214
    if (length($line) <= $pos) {
215
      $line = <$fh>;
216
      return ($text, "") unless ($line);
217
      $pos = 0;
218
    }
219

  
220
    my $cur_char = substr($line, $pos, 1);
221

  
222
    if (!$inside_string) {
223
      if ((length($line) >= ($pos + 3)) && (substr($line, $pos, 2)) eq "qq") {
224
        $inside_string = substr($line, $pos + 2, 1);
225
        $pos += 2;
226

  
227
      } elsif ((length($line) >= ($pos + 2)) &&
228
               (substr($line, $pos, 1) eq "q")) {
229
        $inside_string = substr($line, $pos + 1, 1);
230
        $pos++;
231

  
232
      } elsif (($cur_char eq '"') || ($cur_char eq '\'')) {
233
        $inside_string = $cur_char;
234

  
235
      } elsif ($cur_char eq ")") {
236
        return ($text, substr($line, $pos + 1));
237
      }
238

  
239
    } else {
240
      if ($quote_next) {
241
        $text .= $cur_char;
242
        $quote_next = 0;
243

  
244
      } elsif ($cur_char eq '\\') {
245
        $text .= $cur_char;
246
        $quote_next = 1;
247

  
248
      } elsif ($cur_char eq $inside_string) {
249
        undef($inside_string);
250

  
251
      } else {
252
        $text .= $cur_char;
253

  
254
      }
255
    }
256
    $pos++;
257
  }
258
}
212 259

  
213 260
sub scanfile {
214 261
  my $file = shift;
215 262

  
216 263
  return unless (-f "$file");
217
  
264

  
218 265
  my $fh = new FileHandle;
219 266
  open $fh, "$file" or die "$! : $file";
220 267

  
221 268
  my ($is_submit, $line_no, $sub_line_no) = (0, 0, 0);
222
	
269

  
223 270
  while (<$fh>) {
224 271
    $line_no++;
272

  
225 273
    # is this another file
226 274
    if (/require\s+\W.*\.pl/) {
227 275
      my $newfile = $&;
......
229 277
      $newfile =~ s/\$form->{path}\///;
230 278
      &scanfile("$bindir/$newfile");
231 279
    }
232
   
280

  
233 281
    # is this a sub ?
234 282
    if (/^sub /) {
235 283
      ($null, $subrt) = split / +/;
236 284
      $subrt{$subrt} = 1;
237 285
      next;
238 286
    }
239
    
287

  
240 288
    my $rc = 1;
241
    
289

  
242 290
    while ($rc) {
243 291
      if (/Locale/) {
244
	unless (/^use /) {
245
	  my ($null, $country) = split /,/;
246
	  $country =~ s/^ +[\"\']//;
247
	  $country =~ s/[\"\'].*//;
248
	}
292
        unless (/^use /) {
293
          my ($null, $country) = split /,/;
294
          $country =~ s/^ +[\"\']//;
295
          $country =~ s/[\"\'].*//;
296
        }
249 297
      }
250 298

  
251 299
      my $postmatch = "";
300

  
252 301
      # is it a submit button before $locale->
253 302
      if (/type\s*=\s*submit/i) {
254 303
        $postmatch = $';
255 304
        if ($` !~ /\$locale->text/) {
256
          $is_submit = 1;
305
          $is_submit   = 1;
257 306
          $sub_line_no = $line_no;
258 307
        }
259 308
      }
260 309

  
261
      my ($found) = /\$locale->text.*?\W\)/;
310
      my ($found) = /\$locale->text.*?\(/;
262 311
      my $postmatch = $';
263 312

  
264 313
      if ($found) {
265
	my $string = $&;
266
	$string =~ s/\$locale->text\(\s*[\'\"(q|qq)][\'\/\\\|~]*//;
267
	$string =~ s/\W\)+.*$//;
314
        my $string;
315
        ($string, $_) = extract_text_between_parenthesis($fh, $postmatch);
316
        $postmatch = $_;
268 317

  
269 318
        # if there is no $ in the string record it
270
	unless ($string =~ /\$\D.*/) {
271
	  # this guarantees one instance of string
272
	  $locale{$string} = 1;
319
        unless (($string =~ /\$\D.*/) || ("" eq $string)) {
320

  
321
          # this guarantees one instance of string
322
          $locale{$string} = 1;
273 323

  
274 324
          # this one is for all the locales
275
	  $alllocales{$string} = 1;
325
          $alllocales{$string} = 1;
276 326

  
277 327
          # is it a submit button before $locale->
278 328
          if ($is_submit) {
279
	    $submit{$string} = 1;
329
            $submit{$string} = 1;
280 330
          }
281
	}
331
        }
282 332
      } elsif ($postmatch =~ />/) {
283 333
        $is_submit = 0;
284 334
      }
285 335

  
286 336
      # exit loop if there are no more locales on this line
287 337
      ($rc) = ($postmatch =~ /\$locale->text/);
338

  
288 339
      # strip text
289 340
      s/^.*?\$locale->text.*?\)//;
290 341

  
291
      if (($postmatch =~ />/) ||
292
          (!$found && ($sub_line_no != $line_no) && />/)) {
342
      if (   ($postmatch =~ />/)
343
          || (!$found && ($sub_line_no != $line_no) && />/)) {
293 344
        $is_submit = 0;
294 345
      }
295 346
    }
......
299 350

  
300 351
}
301 352

  
302

  
303 353
sub scanmenu {
304 354
  my $file = shift;
305 355

  
......
311 361

  
312 362
  # strip []
313 363
  grep { s/(\[|\])//g } @a;
314
  
364

  
315 365
  foreach my $item (@a) {
316 366
    @b = split /--/, $item;
317 367
    foreach $string (@b) {
318 368
      chomp $string;
319
      $locale{$string} = 1;
369
      $locale{$string}     = 1;
320 370
      $alllocales{$string} = 1;
321 371
    }
322 372
  }
323
  
324
}
325 373

  
374
}
326 375

  

Auch abrufbar als: Unified diff