- Timestamp:
- 2004-03-07T15:18:16+13:00 (20 years ago)
- Location:
- trunk/gsdl
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gsdl/bin/script/buildcol.pl
r6926 r6945 238 238 } 239 239 240 # Load the appropriate resource bundle for the language specified 241 # If $language is not defined, the default resource bundle will be loaded 242 &gsprintf::load_resource_bundle($language); 240 # If $language has been specified, load the appropriate resource bundle 241 # (Otherwise, the default resource bundle will be loaded automatically) 242 if ($language) { 243 &gsprintf::load_language_specific_resource_bundle($language); 244 } 243 245 244 246 if ($xml) { -
trunk/gsdl/bin/script/classinfo.pl
r6932 r6945 99 99 } 100 100 101 # Load the appropriate resource bundle for the language specified 102 # If $language is not defined, the default resource bundle will be loaded 103 &gsprintf::load_resource_bundle($language); 101 # If $language has been specified, load the appropriate resource bundle 102 # (Otherwise, the default resource bundle will be loaded automatically) 103 if ($language) { 104 &gsprintf::load_language_specific_resource_bundle($language); 105 } 104 106 105 107 # Get classifier -
trunk/gsdl/bin/script/exportcol.pl
r6926 r6945 88 88 } 89 89 90 # Load the appropriate resource bundle for the language specified 91 # If $language is not defined, the default resource bundle will be loaded 92 &gsprintf::load_resource_bundle($language); 90 # If $language has been specified, load the appropriate resource bundle 91 # (Otherwise, the default resource bundle will be loaded automatically) 92 if ($language) { 93 &gsprintf::load_language_specific_resource_bundle($language); 94 } 93 95 94 96 if ($xml) { -
trunk/gsdl/bin/script/import.pl
r6926 r6945 248 248 } 249 249 250 # Load the appropriate resource bundle for the language specified 251 # If $language is not defined, the default resource bundle will be loaded 252 &gsprintf::load_resource_bundle($language); 250 # If $language has been specified, load the appropriate resource bundle 251 # (Otherwise, the default resource bundle will be loaded automatically) 252 if ($language) { 253 &gsprintf::load_language_specific_resource_bundle($language); 254 } 253 255 254 256 if ($xml) { -
trunk/gsdl/bin/script/mkcol.pl
r6926 r6945 211 211 &parse_args (\@ARGV); 212 212 213 # Load the appropriate resource bundle for the language specified 214 # If $language is not defined, the default resource bundle will be loaded 215 &gsprintf::load_resource_bundle($language); 213 # If $language has been specified, load the appropriate resource bundle 214 # (Otherwise, the default resource bundle will be loaded automatically) 215 if ($language) { 216 &gsprintf::load_language_specific_resource_bundle($language); 217 } 216 218 217 219 if ($xml) { -
trunk/gsdl/bin/script/pluginfo.pl
r6932 r6945 82 82 } 83 83 84 # Load the appropriate resource bundle for the language specified 85 # If $language is not defined, the default resource bundle will be loaded 86 &gsprintf::load_resource_bundle($language); 84 # If $language has been specified, load the appropriate resource bundle 85 # (Otherwise, the default resource bundle will be loaded automatically) 86 if ($language) { 87 &gsprintf::load_language_specific_resource_bundle($language); 88 } 87 89 88 90 my $plugin = shift (@ARGV); -
trunk/gsdl/perllib/classify/BasClas.pm
r6932 r6945 94 94 local $self = shift(@_); 95 95 96 # XML output is always in UTF-8 97 &gsprintf::output_strings_in_UTF8; 98 96 99 &PrintUsage::print_xml_header(); 97 100 $self->print_xml(); -
trunk/gsdl/perllib/gsprintf.pm
r6934 r6945 32 32 33 33 34 my $loadedlanguage = "<none>"; 35 my %loadedresourcebundle = (); 36 my $outputencoding; 34 # Language-specific resource bundle 35 my %specialresourcebundle = (); 36 my $specialoutputencoding; 37 38 # Default resource bundle 39 my %defaultresourcebundle; 40 my $defaultoutputencoding; 41 42 # English resource bundle 43 my %englishresourcebundle; 44 my $englishoutputencoding; 45 46 # Ignore the OutputEncoding strings in the resource bundles and output all text in UTF-8 47 my $outputstringsinUTF8 = 0; 37 48 38 49 … … 56 67 my ($stringkey) = @_; 57 68 58 # Load the default resource bundle if one isn't already loaded 59 if ($loadedlanguage eq "<none>") { 60 &load_resource_bundle(""); 61 } 62 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 # Try the language-specific resource bundle first 70 my $utf8string = $specialresourcebundle{$stringkey}; 71 my $outputencoding = $specialoutputencoding; 72 73 # Try the default resource bundle next 74 if (!defined($utf8string)) { 75 # Load the default resource bundle if it is not already loaded 76 &load_default_resource_bundle() if (!%defaultresourcebundle); 77 78 $utf8string = $defaultresourcebundle{$stringkey}; 79 $outputencoding = $defaultoutputencoding; 80 } 81 82 # Try the English resource bundle last 83 if (!defined($utf8string)) { 84 # Load the English resource bundle if it is not already loaded 85 &load_english_resource_bundle() if (!%englishresourcebundle); 86 87 $utf8string = $englishresourcebundle{$stringkey}; 88 $outputencoding = $englishoutputencoding; 89 } 90 91 # No matching string was found, so just return the key 92 if (!defined($utf8string)) { 93 return $stringkey; 94 } 95 96 # Return the string matching the key 97 return $utf8string if (!defined($outputencoding) || $outputstringsinUTF8); 69 98 70 99 # If an 8-bit output encoding has been defined, encode the string appropriately 71 return &unicode::unicode2singlebyte(&unicode::utf82unicode($utf8 _string), $outputencoding);72 } 73 74 75 sub load_ resource_bundle100 return &unicode::unicode2singlebyte(&unicode::utf82unicode($utf8string), $outputencoding); 101 } 102 103 104 sub load_language_specific_resource_bundle 76 105 { 77 106 my $language = shift(@_); 78 107 79 # If the desired resource bundle is the one already loaded, no action is necessary 80 if ($language eq $loadedlanguage) { 81 return; 82 } 83 84 # Open the appropriate resource bundle 108 # Read the specified resource bundle 85 109 my $resourcebundlehome = &util::filename_cat("$ENV{'GSDLHOME'}", "perllib"); 86 110 my $resourcebundlename = "strings_" . $language . ".rb"; 87 111 my $resourcebundlefile = &util::filename_cat($resourcebundlehome, $resourcebundlename); 88 112 89 # If the specific resource bundle cannot be opened, use the generic (English) one 90 if (!open(RESOURCE_BUNDLE, "<$resourcebundlefile")) { 91 $resourcebundlename = "strings.rb"; 92 $resourcebundlefile = &util::filename_cat($resourcebundlehome, $resourcebundlename); 93 open(RESOURCE_BUNDLE, "<$resourcebundlefile") 94 or die "Error: Could not open generic resource bundle $resourcebundlefile.\n"; 95 } 96 113 %specialresourcebundle = &read_resource_bundle($resourcebundlefile); 114 return if (!%specialresourcebundle); 115 116 # Read the output encoding to use from the resource bundle 117 if ($ENV{'GSDLOS'} =~ /windows/) { 118 $specialoutputencoding = $specialresourcebundle{"{OutputEncoding.windows}"}; 119 } 120 else { 121 $specialoutputencoding = $specialresourcebundle{"{OutputEncoding.unix}"}; 122 } 123 } 124 125 126 sub load_default_resource_bundle 127 { 128 # Read the default resource bundle 129 my $resourcebundlehome = &util::filename_cat("$ENV{'GSDLHOME'}", "perllib"); 130 my $resourcebundlename = "strings.rb"; 131 my $resourcebundlefile = &util::filename_cat($resourcebundlehome, $resourcebundlename); 132 133 %defaultresourcebundle = &read_resource_bundle($resourcebundlefile); 134 return if (!%defaultresourcebundle); 135 136 # Read the output encoding to use from the resource bundle 137 if ($ENV{'GSDLOS'} =~ /windows/) { 138 $defaultoutputencoding = $defaultresourcebundle{"{OutputEncoding.windows}"}; 139 } 140 else { 141 $defaultoutputencoding = $defaultresourcebundle{"{OutputEncoding.unix}"}; 142 } 143 } 144 145 146 sub load_english_resource_bundle 147 { 148 # Ensure the English resource bundle hasn't already been loaded 149 if ($specialresourcebundle{"{Language.code}"} eq "en") { 150 $englishresourcebundle = $specialresourcebundle; 151 $englishoutputencoding = $specialoutputencoding; 152 } 153 if ($defaultresourcebundle{"{Language.code}"} eq "en") { 154 $englishresourcebundle = $defaultresourcebundle; 155 $englishoutputencoding = $defaultoutputencoding; 156 } 157 158 # Read the English resource bundle 159 my $resourcebundlehome = &util::filename_cat("$ENV{'GSDLHOME'}", "perllib"); 160 my $resourcebundlename = "strings_en.rb"; 161 my $resourcebundlefile = &util::filename_cat($resourcebundlehome, $resourcebundlename); 162 163 %englishresourcebundle = &read_resource_bundle($resourcebundlefile); 164 return if (!%englishresourcebundle); 165 166 # Read the output encoding to use from the resource bundle 167 if ($ENV{'GSDLOS'} =~ /windows/) { 168 $englishoutputencoding = $englishresourcebundle{"{OutputEncoding.windows}"}; 169 } 170 else { 171 $englishoutputencoding = $englishresourcebundle{"{OutputEncoding.unix}"}; 172 } 173 } 174 175 176 sub read_resource_bundle 177 { 178 my ($resourcebundlefilepath) = shift(@_); 179 180 # Return an empty hash if the specified resource bundle could not be read 181 return () if (!open(RESOURCE_BUNDLE, "<$resourcebundlefilepath")); 182 183 # Load this resource bundle 97 184 my @resourcebundlelines = <RESOURCE_BUNDLE>; 98 185 close(RESOURCE_BUNDLE); 99 186 100 # Load this resource bundle 101 $loadedlanguage = $language; 102 %loadedresourcebundle = (); 187 # Parse the resource bundle 188 my %resourcebundle = (); 103 189 foreach $line (@resourcebundlelines) { 104 190 # Remove any trailing whitespace … … 113 199 114 200 # Map key to text 115 $ loadedresourcebundle{$linekey} = $linetext;201 $resourcebundle{$linekey} = $linetext; 116 202 } 117 203 } 118 204 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(@_); 205 return %resourcebundle; 206 } 207 208 209 sub output_strings_in_UTF8 210 { 211 $outputstringsinUTF8 = 1; 138 212 } 139 213 -
trunk/gsdl/perllib/plugins/BasPlug.pm
r6932 r6945 156 156 local $self = shift(@_); 157 157 158 # XML output is always in UTF-8 159 &gsprintf::output_strings_in_UTF8; 160 158 161 &PrintUsage::print_xml_header(); 159 162 $self->print_xml(); -
trunk/gsdl/perllib/printusage.pm
r6934 r6945 42 42 43 43 # XML output is always in UTF-8 44 my $currentencoding = &gsprintf::get_output_encoding(); 45 &gsprintf::set_output_encoding("UTF-8"); 44 &gsprintf::output_strings_in_UTF8; 46 45 47 46 &print_xml_header(); … … 56 55 &gsprintf(STDERR, " </Arguments>\n"); 57 56 &gsprintf(STDERR, "</Info>\n"); 58 59 # Put the output encoding back to what it was60 &gsprintf::set_output_encoding($currentencoding);61 57 } 62 58
Note:
See TracChangeset
for help on using the changeset viewer.