Changeset 9082
- Timestamp:
- 2005-02-17T15:39:01+13:00 (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/translator.pm
r8102 r9082 55 55 sub read_languages_from_main_cfg_file 56 56 { 57 local%code2namehash = ();57 my %code2namehash = (); 58 58 59 59 # Read the main.cfg file … … 63 63 } 64 64 while (<MAIN_CFG_FILE>) { 65 local$line = $_;65 my $line = $_; 66 66 chomp($line); 67 67 68 68 # Parse the lines containing a language definition 69 69 if ($line =~ m/^Language\s+/i) { 70 local($langcode) = ($line =~ /shortname=(\S+)/i);71 local($langname) = ($line =~ /longname=(\"[^\"]+\"|\S+)/i);70 my ($langcode) = ($line =~ /shortname=(\S+)/i); 71 my ($langname) = ($line =~ /longname=(\"[^\"]+\"|\S+)/i); 72 72 73 73 # Casefold the language code, and remove any quotes around the language name … … 86 86 sub read_translation_files_from_config_file 87 87 { 88 local%name2deschash = ();88 my %name2deschash = (); 89 89 90 90 # Read the translator config file … … 94 94 } 95 95 while (<CONFIG_FILE>) { 96 local$line = $_;96 my $line = $_; 97 97 chomp($line); 98 98 99 99 # Check if a file is being defined 100 100 if ($line =~ m/^File\s+/i) { 101 local($fileid) = ($line =~ /id=(\S+)/i);102 local($filedesc) = ($line =~ /description=(\S+)/i);101 my ($fileid) = ($line =~ /id=(\S+)/i); 102 my ($filedesc) = ($line =~ /description=(\S+)/i); 103 103 $name2deschash{$fileid} = $filedesc; 104 104 } … … 120 120 } 121 121 while (<CONFIG_FILE>) { 122 local$line = $_;122 my $line = $_; 123 123 chomp($line); 124 124 125 125 # Check if a file is being defined 126 126 if ($line =~ m/^File\s+/i) { 127 local@lineparts = split(/\s+/, $line);128 local($fileid) = ($lineparts[1] =~ m/^id=(.*)$/);127 my @lineparts = split(/\s+/, $line); 128 my ($fileid) = ($lineparts[1] =~ m/^id=(.*)$/); 129 129 130 130 # If this is the file we want, return its details 131 131 if ($fileid eq $file) { 132 local($filedesc) = ($lineparts[2] =~ m/^description=(.*)$/);133 local($sourcefile) = ($lineparts[3] =~ m/^sourcefile=(.*)$/);134 local($targetfile) = ($lineparts[4] =~ m/^targetfile=(.*)$/);135 local($filetype) = ($lineparts[5] =~ m/^type=(.*)$/);132 my ($filedesc) = ($lineparts[2] =~ m/^description=(.*)$/); 133 my ($sourcefile) = ($lineparts[3] =~ m/^sourcefile=(.*)$/); 134 my ($targetfile) = ($lineparts[4] =~ m/^targetfile=(.*)$/); 135 my ($filetype) = ($lineparts[5] =~ m/^type=(.*)$/); 136 136 137 137 # Determine sourcebase and targetbase, using the filetype 138 local$sourcebase = &get_file_base($sourceabbr, $filetype);139 local$targetbase = &get_file_base($targetabbr, $filetype);138 my $sourcebase = &get_file_base($sourceabbr, $filetype); 139 my $targetbase = &get_file_base($targetabbr, $filetype); 140 140 141 141 # Resolve instances of {sourceabbr}, {sourcebase}, {targetabbr}, {targetbase} … … 187 187 188 188 # Build a mapping from key to lines 189 local%linehash = &build_key_to_line_mapping($filepath, $filetype);189 my %linehash = &build_key_to_line_mapping($filepath, $filetype); 190 190 191 191 # Build a mapping from chunk key to chunk text, and return … … 221 221 die "\n"; 222 222 } 223 local@lines = <FILE_IN>;223 my @lines = <FILE_IN>; 224 224 close FILE_IN; 225 225 … … 228 228 foreach $key (keys(%linehash)) { 229 229 # Chunk lines in linehash start at 0 230 local$chunkstart = (split(/-/, $linehash{$key}))[0];231 local$chunkfinish = (split(/-/, $linehash{$key}))[1];232 233 local$chunktext = $lines[$chunkstart];230 my $chunkstart = (split(/-/, $linehash{$key}))[0]; 231 my $chunkfinish = (split(/-/, $linehash{$key}))[1]; 232 233 my $chunktext = $lines[$chunkstart]; 234 234 for ($l = ($chunkstart + 1); $l <= $chunkfinish; $l++) { 235 235 $chunktext .= $lines[$l]; … … 246 246 sub import_chunk 247 247 { 248 local($chunktext, $filetype) = @_;248 my ($chunktext, $filetype) = @_; 249 249 250 250 if ($filetype =~ /^macrofile/) { … … 265 265 sub refresh_translation 266 266 { 267 local($translationdir, $sourcefile, $filetype) = @_;267 my ($translationdir, $sourcefile, $filetype) = @_; 268 268 269 269 … … 273 273 274 274 # Parse the backup source language file, building a mapping from chunk key to chunk text 275 local$sourcepath = &get_translation_file_path($translationdir, $sourcefile);276 local%backuphash = &process_file($sourcepath, $filetype);275 my $sourcepath = &get_translation_file_path($translationdir, $sourcefile); 276 my %backuphash = &process_file($sourcepath, $filetype); 277 277 print STDOUT "Number of backup chunks: " . scalar(keys(%backuphash)) . "\n"; 278 278 279 279 # Remove the (possibly out of date) source file 280 local$hotsourcepath = &util::filename_cat($gsdldir, $sourcefile);280 my $hotsourcepath = &util::filename_cat($gsdldir, $sourcefile); 281 281 # &util::rm($hotsourcepath); 282 282 283 283 # Get the latest version of the source file from CVS 284 # local$sourceupdate = `cd $gsdldir; cvs -d $cvsroot update $sourcefile`;284 # my $sourceupdate = `cd $gsdldir; cvs -d $cvsroot update $sourcefile`; 285 285 # if ($sourceupdate !~ /^U /) { 286 286 # print STDERR "Error: Could not update source file.\n"; … … 298 298 299 299 # Parse the new source language file, building a mapping from chunk key to chunk text 300 local%sourcehash = &process_file($sourcepath, $filetype);300 my %sourcehash = &process_file($sourcepath, $filetype); 301 301 print STDOUT "Number of source chunks: " . scalar(keys(%sourcehash)) . "\n"; 302 302 … … 307 307 308 308 # Open the translation database for this file 309 local$translationdb = &util::filename_cat($translationdir, "translation.db");310 local%translationdata = ();309 my $translationdb = &util::filename_cat($translationdir, "translation.db"); 310 my %translationdata = (); 311 311 tie(%translationdata, "GDBM_File", $translationdb, GDBM_WRCREAT, 0666); 312 312 313 313 # Remove translation data for any chunks that no longer exist 314 314 foreach $key (keys(%translationdata)) { 315 local$sourcekey = $key;315 my $sourcekey = $key; 316 316 if ($sourcekey =~ /\*$/) { 317 317 chop($sourcekey); … … 349 349 sub get_macrofile_base 350 350 { 351 local($langcode) = @_;351 my ($langcode) = @_; 352 352 353 353 # List special cases here (macrofile names differ from language longnames) 354 local %specialcases = ('id', 'indo', 355 'pt-br', 'port-br', 356 'pt-pt', 'port-pt', 357 'zh', 'chinese' ); 354 my %specialcases = ('es', 'spanish', 355 'fr', 'french', 356 'id', 'indo', 357 'kz', 'kazakh', 358 'pt-br', 'port-br', 359 'pt-pt', 'port-pt', 360 'ru', 'russian', 361 'zh-tr', 'chinese-trad', 362 'zh', 'chinese' ); 358 363 359 364 # Special cases override main.cfg entries … … 372 377 sub build_key_to_line_mapping_for_macrofile 373 378 { 374 local($filepath) = @_;379 my ($filepath) = @_; 375 380 376 381 # Open file for reading … … 379 384 die "\n"; 380 385 } 381 local@lines = <FILE_IN>;386 my @lines = <FILE_IN>; 382 387 close FILE_IN; 383 388 384 # Initialise some localvariables385 local$currpackage;386 local%linehash = ();389 # Initialise some my variables 390 my $currpackage; 391 my %linehash = (); 387 392 388 393 # Process the contents of the file, line by line 389 394 for ($i = 0; $i < scalar(@lines); $i++) { 390 local$line = $lines[$i];395 my $line = $lines[$i]; 391 396 $line =~ s/(\s*)$//; # Remove any nasty whitespace, carriage returns etc. 392 397 … … 398 403 # Line contains a macro name 399 404 elsif ($line =~ m/^(_\w+_)/) { 400 local $macroname = $1; 405 my $macroname = $1; 406 $line =~ s/\s*([^\\]\#.+)?$//; # Remove any comments and nasty whitespace 401 407 402 408 # While there is still text of the macro to go... 403 local$startline = $i;409 my $startline = $i; 404 410 while ($line !~ /\}$/) { 405 411 $i++; … … 409 415 410 416 # The key consists of the package name and the macro name 411 local$key = $currpackage . "::" . $macroname;417 my $key = $currpackage . "::" . $macroname; 412 418 # Map from key to line 413 419 $linehash{$key} = $startline . "-" . $i; … … 416 422 # Icon: line in format ## "sometext" ## macro ## macroname ## 417 423 elsif ($line =~ m/^\#\# (.*)/) { 418 local$macroname = $1;424 my $macroname = $1; 419 425 420 426 # If the macro text contains a new line it will run over two lines 421 local$startline = $i;427 my $startline = $i; 422 428 unless ($line =~ m/^\#\# .*\#\#/) { 423 429 $i++; … … 427 433 428 434 # Split the image macro header on ## 429 local@names = split(/\s*\#\#\s*/, $macroname);435 my @names = split(/\s*\#\#\s*/, $macroname); 430 436 # Overwrite macroname with macroname from ## ... ## ... ## HERE ### 431 437 $macroname = $names[(scalar @names) - 1]; … … 438 444 439 445 # The key consists of package name and macro name 440 local$key = $currpackage . "::" . $macroname;446 my $key = $currpackage . "::" . $macroname; 441 447 # Map from key to line 442 448 $linehash{$key} = $startline . "-" . ($i - 1); … … 450 456 sub import_chunk_from_macrofile 451 457 { 452 local($chunktext) = @_;458 my ($chunktext) = @_; 453 459 454 460 # Is this an icon macro?? … … 472 478 473 479 # Remove braces enclosing text 474 $chunktext =~ s/^{(\s*)((.|\n)*)}(\s*) /$2/;480 $chunktext =~ s/^{(\s*)((.|\n)*)}(\s*)(\#.+\s*)?/$2/; 475 481 } 476 482 … … 483 489 sub get_resource_bundle_base 484 490 { 485 local($langabbr) = @_;491 my ($langabbr) = @_; 486 492 487 493 return ""; … … 491 497 sub build_key_to_line_mapping_for_resource_bundle 492 498 { 493 local($filepath) = @_;499 my ($filepath) = @_; 494 500 495 501 # Open file for reading … … 498 504 die "\n"; 499 505 } 500 local@lines = <FILE_IN>;506 my @lines = <FILE_IN>; 501 507 close FILE_IN; 502 508 503 # Initialise some localvariables504 local%linehash = ();509 # Initialise some my variables 510 my %linehash = (); 505 511 506 512 # Process the contents of the file, line by line 507 513 for ($i = 0; $i < scalar(@lines); $i++) { 508 local$line = $lines[$i];514 my $line = $lines[$i]; 509 515 $line =~ s/(\s*)$//; # Remove any nasty whitespace, carriage returns etc. 510 516 511 517 # Line contains a dictionary string 512 518 if ($line =~ /^((\w|\.)+):(.*)$/) { 513 local$key = $1;519 my $key = $1; 514 520 515 521 # Map from key to line … … 524 530 sub import_chunk_from_resource_bundle 525 531 { 526 local($chunktext) = @_;532 my ($chunktext) = @_; 527 533 528 534 # Simple: just remove string key … … 538 544 sub build_key_to_line_mapping_for_my_resource_bundle 539 545 { 540 local($filepath) = @_;546 my ($filepath) = @_; 541 547 542 548 # Open file for reading … … 545 551 die "\n"; 546 552 } 547 local@lines = <FILE_IN>;553 my @lines = <FILE_IN>; 548 554 close FILE_IN; 549 555 550 # Initialise some localvariables551 local%linehash = ();556 # Initialise some my variables 557 my %linehash = (); 552 558 553 559 # Process the contents of the file, line by line 554 560 for ($i = 0; $i < scalar(@lines); $i++) { 555 local$line = $lines[$i];561 my $line = $lines[$i]; 556 562 $line =~ s/(\s*)$//; # Remove any nasty whitespace, carriage returns etc. 557 563 558 564 # Line contains a dictionary string 559 565 if ($line =~ /^((\w|\.|\-)+):\"(.*)$/) { 560 local$key = $1;561 local$text = $3;566 my $key = $1; 567 my $text = $3; 562 568 563 569 # While there is still text of the chunk to go... 564 local$startline = $i;570 my $startline = $i; 565 571 while ($text !~ /\"$/ || $text =~ /\\\"$/) { 566 572 $i++; … … 578 584 sub import_chunk_from_my_resource_bundle 579 585 { 580 local($chunktext) = @_;586 my ($chunktext) = @_; 581 587 582 588 # Remove chunk key and quotes
Note:
See TracChangeset
for help on using the changeset viewer.