Changeset 9082


Ignore:
Timestamp:
2005-02-17T15:39:01+13:00 (19 years ago)
Author:
mdewsnip
Message:

Whole lot of changes, mostly changing "local" to "my".

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/translator.pm

    r8102 r9082  
    5555sub read_languages_from_main_cfg_file
    5656{
    57     local %code2namehash = ();
     57    my %code2namehash = ();
    5858
    5959    # Read the main.cfg file
     
    6363    }
    6464    while (<MAIN_CFG_FILE>) {
    65     local $line = $_;
     65    my $line = $_;
    6666    chomp($line);
    6767
    6868    # Parse the lines containing a language definition
    6969    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);
    7272
    7373        # Casefold the language code, and remove any quotes around the language name
     
    8686sub read_translation_files_from_config_file
    8787{
    88     local %name2deschash = ();
     88    my %name2deschash = ();
    8989
    9090    # Read the translator config file
     
    9494    }
    9595    while (<CONFIG_FILE>) {
    96     local $line = $_;
     96    my $line = $_;
    9797    chomp($line);
    9898
    9999    # Check if a file is being defined
    100100    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);
    103103        $name2deschash{$fileid} = $filedesc;
    104104    }
     
    120120    }
    121121    while (<CONFIG_FILE>) {
    122     local $line = $_;
     122    my $line = $_;
    123123    chomp($line);
    124124
    125125    # Check if a file is being defined
    126126    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=(.*)$/);
    129129
    130130        # If this is the file we want, return its details
    131131        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=(.*)$/);
    136136
    137137        # 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);
    140140
    141141        # Resolve instances of {sourceabbr}, {sourcebase}, {targetabbr}, {targetbase}
     
    187187
    188188    # 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);
    190190
    191191    # Build a mapping from chunk key to chunk text, and return
     
    221221    die "\n";
    222222    }
    223     local @lines = <FILE_IN>;
     223    my @lines = <FILE_IN>;
    224224    close FILE_IN;
    225225
     
    228228    foreach $key (keys(%linehash)) {
    229229    # 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];
    234234    for ($l = ($chunkstart + 1); $l <= $chunkfinish; $l++) {
    235235        $chunktext .= $lines[$l];
     
    246246sub import_chunk
    247247{
    248     local ($chunktext, $filetype) = @_;
     248    my ($chunktext, $filetype) = @_;
    249249
    250250    if ($filetype =~ /^macrofile/) {
     
    265265sub refresh_translation
    266266{
    267     local ($translationdir, $sourcefile, $filetype) = @_;
     267    my ($translationdir, $sourcefile, $filetype) = @_;
    268268
    269269
     
    273273
    274274    # 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);
    277277    print STDOUT "Number of backup chunks: " . scalar(keys(%backuphash)) . "\n";
    278278
    279279    # Remove the (possibly out of date) source file
    280     local $hotsourcepath = &util::filename_cat($gsdldir, $sourcefile);
     280    my $hotsourcepath = &util::filename_cat($gsdldir, $sourcefile);
    281281#    &util::rm($hotsourcepath);
    282282
    283283    # 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`;
    285285#    if ($sourceupdate !~ /^U /) {
    286286#   print STDERR "Error: Could not update source file.\n";
     
    298298
    299299    # 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);
    301301    print STDOUT "Number of source chunks: " . scalar(keys(%sourcehash)) . "\n";
    302302
     
    307307
    308308    # 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 = ();
    311311    tie(%translationdata, "GDBM_File", $translationdb, GDBM_WRCREAT, 0666);
    312312
    313313    # Remove translation data for any chunks that no longer exist
    314314    foreach $key (keys(%translationdata)) {
    315     local $sourcekey = $key;
     315    my $sourcekey = $key;
    316316    if ($sourcekey =~ /\*$/) {
    317317        chop($sourcekey);
     
    349349sub get_macrofile_base
    350350{
    351     local ($langcode) = @_;
     351    my ($langcode) = @_;
    352352
    353353    # 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' );
    358363
    359364    # Special cases override main.cfg entries
     
    372377sub build_key_to_line_mapping_for_macrofile
    373378{
    374     local ($filepath) = @_;
     379    my ($filepath) = @_;
    375380
    376381    # Open file for reading
     
    379384    die "\n";
    380385    }
    381     local @lines = <FILE_IN>;
     386    my @lines = <FILE_IN>;
    382387    close FILE_IN;
    383388
    384     # Initialise some local variables
    385     local $currpackage;
    386     local %linehash = ();
     389    # Initialise some my variables
     390    my $currpackage;
     391    my %linehash = ();
    387392
    388393    # Process the contents of the file, line by line
    389394    for ($i = 0; $i < scalar(@lines); $i++) {
    390     local $line = $lines[$i];
     395    my $line = $lines[$i];
    391396    $line =~ s/(\s*)$//;  # Remove any nasty whitespace, carriage returns etc.
    392397
     
    398403    # Line contains a macro name
    399404    elsif ($line =~ m/^(_\w+_)/) {
    400         local $macroname = $1;
     405        my $macroname = $1;
     406        $line =~ s/\s*([^\\]\#.+)?$//;  # Remove any comments and nasty whitespace
    401407
    402408        # While there is still text of the macro to go...
    403         local $startline = $i;
     409        my $startline = $i;
    404410        while ($line !~ /\}$/) {
    405411        $i++;
     
    409415
    410416        # The key consists of the package name and the macro name
    411         local $key = $currpackage . "::" . $macroname;
     417        my $key = $currpackage . "::" . $macroname;
    412418        # Map from key to line
    413419        $linehash{$key} = $startline . "-" . $i;
     
    416422    # Icon: line in format ## "sometext" ## macro ## macroname ##
    417423    elsif ($line =~ m/^\#\# (.*)/) {
    418         local $macroname = $1;
     424        my $macroname = $1;
    419425
    420426        # If the macro text contains a new line it will run over two lines
    421         local $startline = $i;
     427        my $startline = $i;
    422428        unless ($line =~ m/^\#\# .*\#\#/) {
    423429        $i++;
     
    427433
    428434        # Split the image macro header on ##
    429         local @names = split(/\s*\#\#\s*/, $macroname);
     435        my @names = split(/\s*\#\#\s*/, $macroname);
    430436        # Overwrite macroname with macroname from ## ... ## ... ## HERE ###
    431437        $macroname = $names[(scalar @names) - 1];
     
    438444
    439445        # The key consists of package name and macro name
    440         local $key = $currpackage . "::" . $macroname;
     446        my $key = $currpackage . "::" . $macroname;
    441447        # Map from key to line
    442448        $linehash{$key} = $startline . "-" . ($i - 1);
     
    450456sub import_chunk_from_macrofile
    451457{
    452     local ($chunktext) = @_;
     458    my ($chunktext) = @_;
    453459
    454460    # Is this an icon macro??
     
    472478
    473479    # Remove braces enclosing text
    474     $chunktext =~ s/^{(\s*)((.|\n)*)}(\s*)/$2/;
     480    $chunktext =~ s/^{(\s*)((.|\n)*)}(\s*)(\#.+\s*)?/$2/;
    475481    }
    476482
     
    483489sub get_resource_bundle_base
    484490{
    485     local ($langabbr) = @_;
     491    my ($langabbr) = @_;
    486492
    487493    return "";
     
    491497sub build_key_to_line_mapping_for_resource_bundle
    492498{
    493     local ($filepath) = @_;
     499    my ($filepath) = @_;
    494500
    495501    # Open file for reading
     
    498504    die "\n";
    499505    }
    500     local @lines = <FILE_IN>;
     506    my @lines = <FILE_IN>;
    501507    close FILE_IN;
    502508
    503     # Initialise some local variables
    504     local %linehash = ();
     509    # Initialise some my variables
     510    my %linehash = ();
    505511
    506512    # Process the contents of the file, line by line
    507513    for ($i = 0; $i < scalar(@lines); $i++) {
    508     local $line = $lines[$i];
     514    my $line = $lines[$i];
    509515    $line =~ s/(\s*)$//;  # Remove any nasty whitespace, carriage returns etc.
    510516
    511517    # Line contains a dictionary string
    512518    if ($line =~ /^((\w|\.)+):(.*)$/) {
    513         local $key = $1;
     519        my $key = $1;
    514520
    515521        # Map from key to line
     
    524530sub import_chunk_from_resource_bundle
    525531{
    526     local ($chunktext) = @_;
     532    my ($chunktext) = @_;
    527533
    528534    # Simple: just remove string key
     
    538544sub build_key_to_line_mapping_for_my_resource_bundle
    539545{
    540     local ($filepath) = @_;
     546    my ($filepath) = @_;
    541547
    542548    # Open file for reading
     
    545551    die "\n";
    546552    }
    547     local @lines = <FILE_IN>;
     553    my @lines = <FILE_IN>;
    548554    close FILE_IN;
    549555
    550     # Initialise some local variables
    551     local %linehash = ();
     556    # Initialise some my variables
     557    my %linehash = ();
    552558
    553559    # Process the contents of the file, line by line
    554560    for ($i = 0; $i < scalar(@lines); $i++) {
    555     local $line = $lines[$i];
     561    my $line = $lines[$i];
    556562    $line =~ s/(\s*)$//;  # Remove any nasty whitespace, carriage returns etc.
    557563
    558564    # Line contains a dictionary string
    559565    if ($line =~ /^((\w|\.|\-)+):\"(.*)$/) {
    560         local $key = $1;
    561         local $text = $3;
     566        my $key = $1;
     567        my $text = $3;
    562568
    563569        # While there is still text of the chunk to go...
    564         local $startline = $i;
     570        my $startline = $i;
    565571        while ($text !~ /\"$/ || $text =~ /\\\"$/) {
    566572        $i++;
     
    578584sub import_chunk_from_my_resource_bundle
    579585{
    580     local ($chunktext) = @_;
     586    my ($chunktext) = @_;
    581587
    582588    # Remove chunk key and quotes
Note: See TracChangeset for help on using the changeset viewer.