Changeset 6934 for trunk/gsdl/perllib/gsprintf.pm
- Timestamp:
- 2004-03-05T10:52:59+13:00 (20 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/perllib/gsprintf.pm
r6925 r6934 28 28 29 29 30 use unicode; 30 31 use util; 31 32 … … 33 34 my $loadedlanguage = "<none>"; 34 35 my %loadedresourcebundle = (); 36 my $outputencoding; 35 37 36 38 … … 52 54 sub lookup_string 53 55 { 54 local($stringkey) = @_;56 my ($stringkey) = @_; 55 57 56 58 # Load the default resource bundle if one isn't already loaded … … 59 61 } 60 62 61 # Return the text matching the key (or just the key, if no match was found) 62 return $loadedresourcebundle{$stringkey} || $stringkey; 63 # Return just the key if there is no string matching the key 64 return $stringkey if (!defined($loadedresourcebundle{$stringkey})); 65 66 # Otherwise return the string matching the key 67 my $utf8_string = $loadedresourcebundle{$stringkey}; 68 return $utf8_string if (!defined($outputencoding) || $outputencoding eq "UTF-8"); 69 70 # If an 8-bit output encoding has been defined, encode the string appropriately 71 return &unicode::unicode2singlebyte(&unicode::utf82unicode($utf8_string), $outputencoding); 63 72 } 64 73 … … 66 75 sub load_resource_bundle 67 76 { 68 local$language = shift(@_);77 my $language = shift(@_); 69 78 70 79 # If the desired resource bundle is the one already loaded, no action is necessary … … 74 83 75 84 # Open the appropriate resource bundle 76 local$resourcebundlehome = &util::filename_cat("$ENV{'GSDLHOME'}", "perllib");77 local$resourcebundlename = "strings_" . $language . ".rb";78 local$resourcebundlefile = &util::filename_cat($resourcebundlehome, $resourcebundlename);85 my $resourcebundlehome = &util::filename_cat("$ENV{'GSDLHOME'}", "perllib"); 86 my $resourcebundlename = "strings_" . $language . ".rb"; 87 my $resourcebundlefile = &util::filename_cat($resourcebundlehome, $resourcebundlename); 79 88 80 89 # If the specific resource bundle cannot be opened, use the generic (English) one … … 86 95 } 87 96 88 local@resourcebundlelines = <RESOURCE_BUNDLE>;97 my @resourcebundlelines = <RESOURCE_BUNDLE>; 89 98 close(RESOURCE_BUNDLE); 90 99 … … 100 109 # Parse key (everything up to the first colon) 101 110 $line =~ /^([^:]+):(.+)$/; 102 local$linekey = "{" . $1 . "}";103 local$linetext = $2;111 my $linekey = "{" . $1 . "}"; 112 my $linetext = $2; 104 113 105 114 # Map key to text … … 107 116 } 108 117 } 118 119 # Read the output encoding to use from the resource bundle 120 if ($ENV{'GSDLOS'} =~ /windows/) { 121 $outputencoding = $loadedresourcebundle{"{OutputEncoding.windows}"}; 122 } 123 else { 124 $outputencoding = $loadedresourcebundle{"{OutputEncoding.unix}"}; 125 } 126 } 127 128 129 sub get_output_encoding 130 { 131 return $outputencoding; 132 } 133 134 135 sub set_output_encoding 136 { 137 $outputencoding = shift(@_); 109 138 } 110 139
Note:
See TracChangeset
for help on using the changeset viewer.