Changeset 6925 for trunk/gsdl/perllib/gsprintf.pm
- Timestamp:
- 2004-03-04T16:37:57+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/gsprintf.pm
r6920 r6925 31 31 32 32 33 my $loadedlanguage = "<none>"; 34 my %loadedresourcebundle = (); 35 36 33 37 sub gsprintf 34 38 { … … 39 43 40 44 # Look up all the strings in the dictionary 41 $text_string =~ s/(\{[^\}]+\})/&lookup_string( "",$1)/eg;45 $text_string =~ s/(\{[^\}]+\})/&lookup_string($1)/eg; 42 46 43 47 # Resolve the string arguments using sprintf, then write out to the handle … … 48 52 sub lookup_string 49 53 { 50 local ($ language, $stringkey) = @_;54 local ($stringkey) = @_; 51 55 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 } 54 60 55 61 # 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; 57 63 } 58 64 59 60 my $cachedlanguage = "<none>";61 my %cachedresourcebundle = ();62 65 63 66 sub load_resource_bundle … … 65 68 local $language = shift(@_); 66 69 67 # If the desired resource bundle is the one cached, return it68 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; 70 73 } 71 74 … … 86 89 close(RESOURCE_BUNDLE); 87 90 88 # Load and cachethis resource bundle89 $ cachedlanguage = $language;90 % cachedresourcebundle = ();91 # Load this resource bundle 92 $loadedlanguage = $language; 93 %loadedresourcebundle = (); 91 94 foreach $line (@resourcebundlelines) { 92 95 # Remove any trailing whitespace … … 101 104 102 105 # Map key to text 103 $ cachedresourcebundle{$linekey} = $linetext;106 $loadedresourcebundle{$linekey} = $linetext; 104 107 } 105 108 } 106 107 return %cachedresourcebundle;108 109 } 109 110
Note:
See TracChangeset
for help on using the changeset viewer.