Ignore:
Timestamp:
2004-03-04T16:37:57+13:00 (20 years ago)
Author:
mdewsnip
Message:

Changed the way display in different languages is done. Instead of passing a language variable throughout the process, the desired resource bundle is explicitly loaded during the initialization of each program (buildcol.pl, classinfo.pl, exportcol.pl, import.pl mkcol.pl, pluginfo.pl).

File:
1 edited

Legend:

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

    r6920 r6925  
    3131
    3232
     33my $loadedlanguage = "<none>";
     34my %loadedresourcebundle = ();
     35
     36
    3337sub gsprintf
    3438{
     
    3943
    4044    # Look up all the strings in the dictionary
    41     $text_string =~ s/(\{[^\}]+\})/&lookup_string("", $1)/eg;
     45    $text_string =~ s/(\{[^\}]+\})/&lookup_string($1)/eg;
    4246
    4347    # Resolve the string arguments using sprintf, then write out to the handle
     
    4852sub lookup_string
    4953{
    50     local ($language, $stringkey) = @_;
     54    local ($stringkey) = @_;
    5155
    52     # Load the default resource bundle
    53     local %resourcebundle = &load_resource_bundle($language);
     56    # Load the default resource bundle if one isn't already loaded
     57    if ($loadedlanguage eq "<none>") {
     58    &load_resource_bundle("");
     59    }
    5460
    5561    # Return the text matching the key (or just the key, if no match was found)
    56     return $resourcebundle{$stringkey} || $stringkey;
     62    return $loadedresourcebundle{$stringkey} || $stringkey;
    5763}
    5864
    59 
    60 my $cachedlanguage = "<none>";
    61 my %cachedresourcebundle = ();
    6265
    6366sub load_resource_bundle
     
    6568    local $language = shift(@_);
    6669
    67     # If the desired resource bundle is the one cached, return it
    68     if ($language eq $cachedlanguage) {
    69     return %cachedresourcebundle;
     70    # If the desired resource bundle is the one already loaded, no action is necessary
     71    if ($language eq $loadedlanguage) {
     72    return;
    7073    }
    7174
     
    8689    close(RESOURCE_BUNDLE);
    8790
    88     # Load and cache this resource bundle
    89     $cachedlanguage = $language;
    90     %cachedresourcebundle = ();
     91    # Load this resource bundle
     92    $loadedlanguage = $language;
     93    %loadedresourcebundle = ();
    9194    foreach $line (@resourcebundlelines) {
    9295    # Remove any trailing whitespace
     
    101104
    102105        # Map key to text
    103         $cachedresourcebundle{$linekey} = $linetext;
     106        $loadedresourcebundle{$linekey} = $linetext;
    104107    }
    105108    }
    106 
    107     return %cachedresourcebundle;
    108109}
    109110
Note: See TracChangeset for help on using the changeset viewer.