Changeset 5682 for trunk


Ignore:
Timestamp:
2003-10-20T15:08:01+13:00 (21 years ago)
Author:
mdewsnip
Message:

Changed to use the gsprintf module, which makes using strings from the resource bundle much easier.

Location:
trunk/gsdl/perllib
Files:
3 edited

Legend:

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

    r2024 r5682  
    2929
    3030require util;
     31use gsprintf;
     32
     33
     34sub gsprintf
     35{
     36    return &gsprintf::gsprintf(@_);
     37}
    3138
    3239
     
    5158    if (-e $colclassname) { require $colclassname; }
    5259    elsif (-e $mainclassname) { require $mainclassname; }
    53     else { die "ERROR - couldn't find classifier \"$classname\"\n"; }
     60    else { &gsprintf(STDERR, "{classify.could_not_find_classifier}\n", $classname) && die "\n";
     61           # die "ERROR - couldn't find classifier \"$classname\"\n";
     62       }
    5463
    5564    # create the classify object
  • trunk/gsdl/perllib/plugin.pm

    r3402 r5682  
    2727
    2828require util;
     29use gsprintf;
    2930
    3031my $stats = {'num_processed' => 0,
     
    3334         'num_archives' => 0
    3435         };
     36
     37
     38sub gsprintf
     39{
     40    return &gsprintf::gsprintf(@_);
     41}
     42
    3543
    3644sub load_plugins {
     
    5462    if (-e $colplugname) { require $colplugname; }
    5563    elsif (-e $mainplugname) { require $mainplugname; }
    56     else { die "ERROR - couldn't find plugin \"$pluginname\"\n"; }
     64    else { &gsprintf(STDERR, "{plugin.could_not_find_plugin}\n", $pluginname) && die "\n";
     65           # die "ERROR - couldn't find plugin \"$pluginname\"\n";
     66       }
    5767
    5868    # create a plugin object
     
    90100    # an import.pl or buildcol.pl process
    91101    if (-e &util::filename_cat ($ENV{'GSDLCOLLECTDIR'}, ".kill")) {
    92     print $outhandle "Process killed by .kill file\n";
     102    &gsprintf($outhandle, "{plugin.kill_file}\n");
     103    # print $outhandle "Process killed by .kill file\n";
    93104    die "\n";
    94105    }
     
    103114
    104115    if ($verbosity >= 2) {
    105     print $outhandle "WARNING - no plugin could process $file\n";
     116    &gsprintf($outhandle, "{plugin.no_plugin_could_process}\n", $file);
     117    # print $outhandle "WARNING - no plugin could process $file\n";
    106118    }
    107119   
    108120    $file =~ s/.*?([^\\\/]+)$/$1/;
    109     print $failhandle "$file: no plugin could process this file\n";
     121    &gsprintf($failhandle, "$file: {plugin.no_plugin_could_process_this_file}\n");
     122    # print $failhandle "$file: no plugin could process this file\n";
    110123    $stats->{'num_not_processed'} ++;
    111124
     
    127140
    128141    if ($total == 1) {
    129     print $statshandle "* 1 document was considered for processing\n";
     142    &gsprintf($statshandle, "* {plugin.one_considered}\n");
     143    # print $statshandle "* 1 document was considered for processing\n";
    130144    } else {
    131     print $statshandle "* $total documents were considered for processing\n";
     145    &gsprintf($statshandle, "* {plugin.n_considered}\n", $total);
     146    # print $statshandle "* $total documents were considered for processing\n";
    132147    }
    133148    if ($stats->{'num_archives'}) {
    134     print $statshandle "   (including the contents of " . $stats->{'num_archives'} .
    135         " ZIP/TAR archive";
    136     if ($stats->{'num_archives'} == 1) {print $statshandle ")\n";}
    137     else {print $statshandle "s)\n";}
     149    # print $statshandle "   (including the contents of " . $stats->{'num_archives'} .
     150    #     " ZIP/TAR archive";
     151    if ($stats->{'num_archives'} == 1) {
     152        &gsprintf($statshandle, "   ({plugin.including_archive})\n");
     153        # print $statshandle ")\n";}
     154    }
     155    else {
     156        &gsprintf($statshandle, "   ({plugin.including_archives})\n", $stats->{'num_archives'});
     157        # print $statshandle "s)\n";}
     158    }
    138159    }
    139160    if ($stats->{'num_processed'} == 1) {
    140     print $statshandle "* 1 was processed and included in the collection\n";
     161    &gsprintf($statshandle, "* {plugin.one_included}\n");
     162    # print $statshandle "* 1 was processed and included in the collection\n";
    141163    } else {
    142     print $statshandle "* " . $stats->{'num_processed'} . " were processed and included in the collection\n";
     164    &gsprintf($statshandle, "* {plugin.n_included}\n", $stats->{'num_processed'});
     165    # print $statshandle "* " . $stats->{'num_processed'} . " were processed and included in the collection\n";
    143166    }
    144167    if ($stats->{'num_not_processed'}) {
    145168    if ($stats->{'num_not_processed'} == 1) {
    146         print $statshandle "* 1 was rejected.";
     169        &gsprintf($statshandle, "* {plugin.one_rejected}\n");
     170        # print $statshandle "* 1 was rejected.";
    147171    } else {
    148         print $statshandle "* " . $stats->{'num_not_processed'} . " were rejected.";
    149     }
    150     print $statshandle " See $faillog for a list of rejected documents\n";
     172        &gsprintf($statshandle, "* {plugin.n_rejected}\n", $stats->{'num_not_processed'});
     173        # print $statshandle "* " . $stats->{'num_not_processed'} . " were rejected.";
     174    }
     175    &gsprintf($statshandle, " {plugin.see_faillog}\n", $faillog);
     176    # print $statshandle " See $faillog for a list of rejected documents\n";
    151177    }
    152178}
  • trunk/gsdl/perllib/printusage.pm

    r4873 r5682  
    2626
    2727package PrintUsage;
     28
     29
     30use gsprintf;
    2831
    2932
     
    5356    foreach $option (@$options) {
    5457    local $optionname = $option->{'name'};
    55     local $optiondesc = &lookup_string($language, $option->{'desc'});
     58    local $optiondesc = &gsprintf::lookup_string($language, $option->{'desc'});
    5659
    5760    # Escape '<' and '>' characters
     
    7881        print STDERR "          <Name>$optionvalue->{'name'}</Name>\n";
    7982        if (defined $optionvalue->{'desc'}) {
    80             local $optionvaluedesc = &lookup_string($language, $optionvalue->{'desc'});
     83            local $optionvaluedesc = &gsprintf::lookup_string($language, $optionvalue->{'desc'});
    8184
    8285            # Escape '<' and '>' characters
     
    156159
    157160    # Display the option description
    158     local $optiondesc = &lookup_string($language, $option->{'desc'});
     161    local $optiondesc = &gsprintf::lookup_string($language, $option->{'desc'});
    159162    local $optionreqd = $option->{'reqd'};
    160163    if (defined($optionreqd) && $optionreqd eq "yes") {
    161         $optiondesc = "(REQUIRED) " . $optiondesc;
     164        $optiondesc = "(" . &gsprintf::lookup_string($language, "{PrintUsage.required}") . ") " . $optiondesc;
    162165    }
    163166    &display_text_in_column($optiondesc, $optiondescoffset, $optionstringlength, 80);
     
    167170    if (defined($optiondefault)) {
    168171        print STDERR " " x $optiondescoffset;
    169         print STDERR "Default: " . $optiondefault . "\n";
     172        print STDERR &gsprintf::lookup_string($language, "{PrintUsage.default}");
     173        print STDERR ": " . $optiondefault . "\n";
    170174    }
    171175
     
    179183        print STDERR "$optionvaluename:";
    180184
    181         local $optionvaluedesc = &lookup_string($language, $optionvalue->{'desc'});
     185        local $optionvaluedesc = &gsprintf::lookup_string($language, $optionvalue->{'desc'});
    182186        &display_text_in_column($optionvaluedesc, $optiondescoffset + 2,
    183187                    $optiondescoffset + length($optionvaluename), 80);
     
    204208
    205209
    206 sub lookup_string
    207 {
    208     local ($language, $stringkey) = @_;
    209 
    210     # Load the appropriate resource bundle
    211     local %resourcebundle = &load_resource_bundle($language);
    212 
    213     # Return the text matching the key (or just the key, if no match was found)
    214     return $resourcebundle{$stringkey} || $stringkey;
    215 }
    216 
    217 
    218 my $cachedlanguage = "<none>";
    219 my %cachedresourcebundle = ();
    220 
    221 sub load_resource_bundle
    222 {
    223     local $language = shift(@_);
    224 
    225     # If the desired resource bundle is the one cached, return it
    226     if ($language eq $cachedlanguage) {
    227     return %cachedresourcebundle;
    228     }
    229 
    230     # Open the appropriate resource bundle
    231     local $resourcebundlehome = &util::filename_cat("$ENV{'GSDLHOME'}", "perllib");
    232     local $resourcebundlename = "strings_" . $language . ".rb";
    233     local $resourcebundlefile = &util::filename_cat($resourcebundlehome, $resourcebundlename);
    234 
    235     # If the specific resource bundle cannot be opened, use the generic (English) one
    236     if (!open(RESOURCE_BUNDLE, "<$resourcebundlefile")) {
    237     $resourcebundlename = "strings.rb";
    238     $resourcebundlefile = &util::filename_cat($resourcebundlehome, $resourcebundlename);
    239     open(RESOURCE_BUNDLE, "<$resourcebundlefile")
    240         or die "Error: Could not open generic resource bundle $resourcebundlefile.\n";
    241     }
    242 
    243     local @resourcebundlelines = <RESOURCE_BUNDLE>;
    244     close(RESOURCE_BUNDLE);
    245 
    246     # Load and cache this resource bundle
    247     $cachedlanguage = $language;
    248     %cachedresourcebundle = ();
    249     foreach $line (@resourcebundlelines) {
    250     # Remove any trailing whitespace
    251     $line =~ s/(\s*)$//;
    252 
    253     # Ignore comments and empty lines
    254     if ($line !~ /^\#/ && $line ne "") {
    255         # Parse key (everything up to the first colon)
    256         $line =~ /^([^:]+):(.+)$/;
    257         local $linekey = "{" . $1 . "}";
    258         local $linetext = $2;
    259 
    260         # Map key to text
    261         $cachedresourcebundle{$linekey} = $linetext;
    262     }
    263     }
    264 
    265     return %cachedresourcebundle;
    266 }
    267 
    268 
    269210sub display_text_in_column
    270211{
Note: See TracChangeset for help on using the changeset viewer.