Changeset 5682 for trunk/gsdl/perllib/printusage.pm
- Timestamp:
- 2003-10-20T15:08:01+13:00 (21 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/printusage.pm
r4873 r5682 26 26 27 27 package PrintUsage; 28 29 30 use gsprintf; 28 31 29 32 … … 53 56 foreach $option (@$options) { 54 57 local $optionname = $option->{'name'}; 55 local $optiondesc = & lookup_string($language, $option->{'desc'});58 local $optiondesc = &gsprintf::lookup_string($language, $option->{'desc'}); 56 59 57 60 # Escape '<' and '>' characters … … 78 81 print STDERR " <Name>$optionvalue->{'name'}</Name>\n"; 79 82 if (defined $optionvalue->{'desc'}) { 80 local $optionvaluedesc = & lookup_string($language, $optionvalue->{'desc'});83 local $optionvaluedesc = &gsprintf::lookup_string($language, $optionvalue->{'desc'}); 81 84 82 85 # Escape '<' and '>' characters … … 156 159 157 160 # Display the option description 158 local $optiondesc = & lookup_string($language, $option->{'desc'});161 local $optiondesc = &gsprintf::lookup_string($language, $option->{'desc'}); 159 162 local $optionreqd = $option->{'reqd'}; 160 163 if (defined($optionreqd) && $optionreqd eq "yes") { 161 $optiondesc = "( REQUIRED) " . $optiondesc;164 $optiondesc = "(" . &gsprintf::lookup_string($language, "{PrintUsage.required}") . ") " . $optiondesc; 162 165 } 163 166 &display_text_in_column($optiondesc, $optiondescoffset, $optionstringlength, 80); … … 167 170 if (defined($optiondefault)) { 168 171 print STDERR " " x $optiondescoffset; 169 print STDERR "Default: " . $optiondefault . "\n"; 172 print STDERR &gsprintf::lookup_string($language, "{PrintUsage.default}"); 173 print STDERR ": " . $optiondefault . "\n"; 170 174 } 171 175 … … 179 183 print STDERR "$optionvaluename:"; 180 184 181 local $optionvaluedesc = & lookup_string($language, $optionvalue->{'desc'});185 local $optionvaluedesc = &gsprintf::lookup_string($language, $optionvalue->{'desc'}); 182 186 &display_text_in_column($optionvaluedesc, $optiondescoffset + 2, 183 187 $optiondescoffset + length($optionvaluename), 80); … … 204 208 205 209 206 sub lookup_string207 {208 local ($language, $stringkey) = @_;209 210 # Load the appropriate resource bundle211 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_bundle222 {223 local $language = shift(@_);224 225 # If the desired resource bundle is the one cached, return it226 if ($language eq $cachedlanguage) {227 return %cachedresourcebundle;228 }229 230 # Open the appropriate resource bundle231 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) one236 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 bundle247 $cachedlanguage = $language;248 %cachedresourcebundle = ();249 foreach $line (@resourcebundlelines) {250 # Remove any trailing whitespace251 $line =~ s/(\s*)$//;252 253 # Ignore comments and empty lines254 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 text261 $cachedresourcebundle{$linekey} = $linetext;262 }263 }264 265 return %cachedresourcebundle;266 }267 268 269 210 sub display_text_in_column 270 211 {
Note:
See TracChangeset
for help on using the changeset viewer.