Changeset 17533 for gsdl/trunk/perllib/gsprintf.pm
- Timestamp:
- 2008-10-15T12:27:10+13:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
gsdl/trunk/perllib/gsprintf.pm
r16635 r17533 77 77 # Try the default resource bundle next 78 78 if (!defined($utf8string)) { 79 80 81 82 83 79 # Load the default resource bundle if it is not already loaded 80 &load_default_resource_bundle() if (!%defaultresourcebundle); 81 82 $utf8string = $defaultresourcebundle{$stringkey}; 83 $outputencoding = $defaultoutputencoding; 84 84 } 85 85 86 86 # Try the English resource bundle last 87 87 if (!defined($utf8string)) { 88 89 90 91 92 88 # Load the English resource bundle if it is not already loaded 89 &load_english_resource_bundle() if (!%englishresourcebundle); 90 91 $utf8string = $englishresourcebundle{$stringkey}; 92 $outputencoding = $englishoutputencoding; 93 93 } 94 94 95 95 # No matching string was found, so just return the key 96 96 if (!defined($utf8string)) { 97 97 return $stringkey; 98 98 } 99 99 100 100 # Return the string matching the key 101 101 return $utf8string if (!defined($outputencoding) || $outputstringsinUTF8 102 102 || $outputencoding eq "utf8"); 103 103 104 104 # If an 8-bit output encoding has been defined, encode the string appropriately … … 128 128 # Read the output encoding to use from the resource bundle 129 129 if ($ENV{'GSDLOS'} =~ /windows/) { 130 130 $specialoutputencoding = $specialresourcebundle{"{OutputEncoding.windows}"}; 131 131 } 132 132 else { 133 134 135 136 137 138 139 140 141 142 143 144 145 133 # see if there is an encoding set in the appropriate locale env var 134 135 foreach my $envvar ('LC_ALL', 'LANG') { 136 if (!exists $ENV{$envvar}) { next } 137 my $locale=$ENV{$envvar}; 138 if ($locale !~ /^\w+\.(.+)$/) { next } 139 my $enc=lc($1); 140 $enc =~ s/-/_/g; 141 if ($enc eq 'utf_8') { $enc='utf8' } # normalise to this name 142 $specialoutputencoding = $enc; 143 return; 144 } 145 $specialoutputencoding = $specialresourcebundle{"{OutputEncoding.unix}"}; 146 146 } 147 147 } … … 159 159 # $! will still have the error value for the last failed syscall 160 160 print STDERR "$! $resourcebundlefile\n"; 161 162 161 # set something so we don't bother trying to load it again 162 $defaultresourcebundle{0}=undef; 163 163 return; 164 164 } … … 166 166 # Read the output encoding to use from the resource bundle 167 167 if ($ENV{'GSDLOS'} =~ /windows/) { 168 168 $defaultoutputencoding = $defaultresourcebundle{"{OutputEncoding.windows}"}; 169 169 } 170 170 else { 171 171 $defaultoutputencoding = $defaultresourcebundle{"{OutputEncoding.unix}"}; 172 172 } 173 173 } … … 178 178 # Ensure the English resource bundle hasn't already been loaded 179 179 if (%specialresourcebundle && $specialresourcebundle{"{Language.code}"} eq "en") { 180 181 180 %englishresourcebundle = %specialresourcebundle; 181 $englishoutputencoding = $specialoutputencoding; 182 182 } 183 183 184 184 if ($defaultresourcebundle{"{Language.code}"} && 185 186 187 185 $defaultresourcebundle{"{Language.code}"} eq "en") { 186 %englishresourcebundle = %defaultresourcebundle; 187 $englishoutputencoding = $defaultoutputencoding; 188 188 } 189 189 … … 198 198 # Read the output encoding to use from the resource bundle 199 199 if ($ENV{'GSDLOS'} =~ /windows/) { 200 200 $englishoutputencoding = $englishresourcebundle{"{OutputEncoding.windows}"}; 201 201 } 202 202 else { 203 203 $englishoutputencoding = $englishresourcebundle{"{OutputEncoding.unix}"}; 204 204 } 205 205 } … … 220 220 my %resourcebundle = (); 221 221 foreach my $line (@resourcebundlelines) { 222 # Remove any trailing whitespace 223 $line =~ s/(\s*)$//; 224 225 # Ignore comments and empty lines 226 if ($line !~ /^\#/ && $line ne "") { 227 # Parse key (everything up to the first colon) 228 $line =~ /^([^:]+):(.+)$/; 229 my $linekey = "{" . $1 . "}"; 230 my $linetext = $2; 231 $linetext =~ s/(\s*)\#\s+Updated\s+(\d?\d-\D\D\D-\d\d\d\d).*$//i; 232 233 # Map key to text 234 $resourcebundle{$linekey} = $linetext; 235 } 222 # Remove any trailing whitespace 223 $line =~ s/(\s*)$//; 224 225 # Ignore comments and empty lines 226 if ($line !~ /^\#/ && $line ne "") { 227 # Parse key (everything up to the first colon) 228 if ($line =~ m/^([^:]+):(.+)$/) { 229 my $linekey = "{" . $1 . "}"; 230 my $linetext = $2; 231 $linetext =~ s/(\s*)\#\s+Updated\s+(\d?\d-\D\D\D-\d\d\d\d).*$//i; 232 233 # Map key to text 234 $resourcebundle{$linekey} = $linetext; 235 } 236 } 236 237 } 237 238 … … 249 250 { 250 251 join("", 251 252 253 254 252 map { $_ > 255 ? # if wide character... 253 sprintf("\\x{%04X}", $_) : # \x{...} 254 chr($_) 255 } unpack("U*", $_[0])); # unpack Unicode characters 255 256 } 256 257
Note:
See TracChangeset
for help on using the changeset viewer.