Index: gsdl/trunk/perllib/gsprintf.pm
===================================================================
--- gsdl/trunk/perllib/gsprintf.pm	(revision 17533)
+++ gsdl/trunk/perllib/gsprintf.pm	(revision 18981)
@@ -58,5 +58,5 @@
     # Return unless the required arguments were supplied
     return unless (defined($handle) && defined($text_string));
-
+    
     # Look up all the strings in the dictionary
     $text_string =~ s/(\{[^\}]+\})/&lookup_string($1)/eg;
@@ -77,29 +77,29 @@
     # Try the default resource bundle next
     if (!defined($utf8string)) {
-    # Load the default resource bundle if it is not already loaded
-    &load_default_resource_bundle() if (!%defaultresourcebundle);
-
-    $utf8string = $defaultresourcebundle{$stringkey};
-    $outputencoding = $defaultoutputencoding;
-    }
-
+	# Load the default resource bundle if it is not already loaded
+	&load_default_resource_bundle() if (!%defaultresourcebundle);
+	
+	$utf8string = $defaultresourcebundle{$stringkey};
+	$outputencoding = $defaultoutputencoding;
+    }
+    
     # Try the English resource bundle last
     if (!defined($utf8string)) {
-    # Load the English resource bundle if it is not already loaded
-    &load_english_resource_bundle() if (!%englishresourcebundle);
-
-    $utf8string = $englishresourcebundle{$stringkey};
-    $outputencoding = $englishoutputencoding;
-    }
-
+	# Load the English resource bundle if it is not already loaded
+	&load_english_resource_bundle() if (!%englishresourcebundle);
+	
+	$utf8string = $englishresourcebundle{$stringkey};
+	$outputencoding = $englishoutputencoding;
+    }
+    
     # No matching string was found, so just return the key
     if (!defined($utf8string)) {
-    return $stringkey;
-    }
-
+	return $stringkey;
+    }
+    
     # Return the string matching the key
     return $utf8string if (!defined($outputencoding) || $outputstringsinUTF8
-               || $outputencoding eq "utf8");
-
+			   || $outputencoding eq "utf8");
+    
     # If an 8-bit output encoding has been defined, encode the string appropriately
     my $encoded=unicode::unicode2singlebyte(&unicode::utf82unicode($utf8string), $outputencoding);
@@ -107,5 +107,5 @@
     # If we successfully encoded it, return it
     if ($encoded) { return $encoded }
-
+    
     # Otherwise, we can't convert to the requested encoding. return the utf8?
     $specialoutputencoding='utf8';
@@ -117,31 +117,30 @@
 {
     my $language = shift(@_);
-
+    
     # Read the specified resource bundle
-    my $resourcebundlehome = &util::filename_cat("$ENV{'GSDLHOME'}", "perllib");
     my $resourcebundlename = "strings_" . $language . ".properties";
-    my $resourcebundlefile = &util::filename_cat($resourcebundlehome, $resourcebundlename);
-
-    %specialresourcebundle = &read_resource_bundle($resourcebundlefile);
+    
+    %specialresourcebundle 
+	= &read_resource_bundle_and_extensions($ENV{'GSDLHOME'},"perllib",$resourcebundlename);
     return if (!%specialresourcebundle);
-
+    
     # Read the output encoding to use from the resource bundle
     if ($ENV{'GSDLOS'} =~ /windows/) {
-    $specialoutputencoding = $specialresourcebundle{"{OutputEncoding.windows}"};
+	$specialoutputencoding = $specialresourcebundle{"{OutputEncoding.windows}"};
     }
     else {
-    # see if there is an encoding set in the appropriate locale env var
-
-    foreach my $envvar ('LC_ALL', 'LANG') {
-        if (!exists $ENV{$envvar}) { next }
-        my $locale=$ENV{$envvar};
-        if ($locale !~ /^\w+\.(.+)$/) { next }
-        my $enc=lc($1);
-        $enc =~ s/-/_/g;
-        if ($enc eq 'utf_8') { $enc='utf8' } # normalise to this name
-        $specialoutputencoding = $enc;
-        return;
-    }
-    $specialoutputencoding = $specialresourcebundle{"{OutputEncoding.unix}"};
+	# see if there is an encoding set in the appropriate locale env var
+	
+	foreach my $envvar ('LC_ALL', 'LANG') {
+	    if (!exists $ENV{$envvar}) { next }
+	    my $locale=$ENV{$envvar};
+	    if ($locale !~ /^\w+\.(.+)$/) { next }
+	    my $enc=lc($1);
+	    $enc =~ s/-/_/g;
+	    if ($enc eq 'utf_8') { $enc='utf8' } # normalise to this name
+	    $specialoutputencoding = $enc;
+	    return;
+	}
+	$specialoutputencoding = $specialresourcebundle{"{OutputEncoding.unix}"};
     }
 }
@@ -151,23 +150,22 @@
 {
     # Read the default resource bundle
-    my $resourcebundlehome = &util::filename_cat("$ENV{'GSDLHOME'}", "perllib");
     my $resourcebundlename = "strings.properties";
-    my $resourcebundlefile = &util::filename_cat($resourcebundlehome, $resourcebundlename);
-
-    %defaultresourcebundle = &read_resource_bundle($resourcebundlefile);
+
+    %defaultresourcebundle 
+	= &read_resource_bundle_and_extensions($ENV{'GSDLHOME'},"perllib",$resourcebundlename);
     if (!%defaultresourcebundle) {
         # $! will still have the error value for the last failed syscall
-        print STDERR "$! $resourcebundlefile\n";
-    # set something so we don't bother trying to load it again
-    $defaultresourcebundle{0}=undef; 
+        print STDERR "$! $resourcebundlename\n";
+	# set something so we don't bother trying to load it again
+	$defaultresourcebundle{0}=undef; 
         return;
     }
-
+    
     # Read the output encoding to use from the resource bundle
     if ($ENV{'GSDLOS'} =~ /windows/) {
-    $defaultoutputencoding = $defaultresourcebundle{"{OutputEncoding.windows}"};
+	$defaultoutputencoding = $defaultresourcebundle{"{OutputEncoding.windows}"};
     }
     else {
-    $defaultoutputencoding = $defaultresourcebundle{"{OutputEncoding.unix}"};
+	$defaultoutputencoding = $defaultresourcebundle{"{OutputEncoding.unix}"};
     }
 }
@@ -178,29 +176,54 @@
     # Ensure the English resource bundle hasn't already been loaded
     if (%specialresourcebundle && $specialresourcebundle{"{Language.code}"} eq "en") {
-    %englishresourcebundle = %specialresourcebundle;
-    $englishoutputencoding = $specialoutputencoding;
+	%englishresourcebundle = %specialresourcebundle;
+	$englishoutputencoding = $specialoutputencoding;
     }
     
     if ($defaultresourcebundle{"{Language.code}"} &&
         $defaultresourcebundle{"{Language.code}"} eq "en") {
-    %englishresourcebundle = %defaultresourcebundle;
-    $englishoutputencoding = $defaultoutputencoding;
-    }
-
+	%englishresourcebundle = %defaultresourcebundle;
+	$englishoutputencoding = $defaultoutputencoding;
+    }
+    
     # Read the English resource bundle
-    my $resourcebundlehome = &util::filename_cat("$ENV{'GSDLHOME'}", "perllib");
     my $resourcebundlename = "strings_en.properties";
-    my $resourcebundlefile = &util::filename_cat($resourcebundlehome, $resourcebundlename);
-
-    %englishresourcebundle = &read_resource_bundle($resourcebundlefile);
+
+    %englishresourcebundle 
+	= &read_resource_bundle_and_extensions($ENV{'GSDLHOME'},"perllib",$resourcebundlename);
     return if (!%englishresourcebundle);
-
+    
     # Read the output encoding to use from the resource bundle
     if ($ENV{'GSDLOS'} =~ /windows/) {
-    $englishoutputencoding = $englishresourcebundle{"{OutputEncoding.windows}"};
+	$englishoutputencoding = $englishresourcebundle{"{OutputEncoding.windows}"};
     }
     else {
-    $englishoutputencoding = $englishresourcebundle{"{OutputEncoding.unix}"};
-    }
+	$englishoutputencoding = $englishresourcebundle{"{OutputEncoding.unix}"};
+    }
+}
+
+
+sub read_resource_bundle_and_extensions
+{
+    my ($bundle_base,$primary_dir,$resourcename) = @_;
+
+    my $primary_resourcebundlefile 
+	= &util::filename_cat($bundle_base,$primary_dir,$resourcename);
+
+    my $resourcebundle = read_resource_bundle($primary_resourcebundlefile);
+    return if (!defined $resourcebundle);
+
+    my @extensions = split(/:/,$ENV{'GSDLEXTS'});
+    foreach my $e (@extensions) {	
+	my $ext_base
+	    = &util::filename_cat($bundle_base,"ext",$e);
+
+	my $ext_resourcebundlefile 
+	    = &util::filename_cat($ext_base,$primary_dir,$resourcename);
+
+	# can ignore return value (will be same reference to $resourcebundle)
+	read_resource_bundle($ext_resourcebundlefile,$resourcebundle);
+    }
+    
+    return %$resourcebundle;
 }
 
@@ -208,9 +231,22 @@
 sub read_resource_bundle
 {
-    my ($resourcebundlefilepath) = shift(@_);
-
-    # Return an empty hash if the specified resource bundle could not be read
-    return () if (!open(RESOURCE_BUNDLE, "<$resourcebundlefilepath"));
-
+    my ($resourcebundlefilepath,$resourcebundle) = @_;
+
+    if (!open(RESOURCE_BUNDLE, "<$resourcebundlefilepath")) {
+	# When called for the first time (primary resource), $resourcebundle
+	# is not defined (=undef). If the file does not exist, then we return
+	# this 'undef' to signal it was not found
+	# For an extension resource bundle, if it does not exist this
+	# is not so serious (in fact quite likely) => return what we 
+	# have built up so far
+	
+	return $resourcebundle;
+    }
+
+    if (!defined $resourcebundle) {	
+	# resource files exists, so exect some content to be stored
+	$resourcebundle = {};
+    }
+    
     # Load this resource bundle
     my @resourcebundlelines = <RESOURCE_BUNDLE>;
@@ -218,5 +254,5 @@
 
     # Parse the resource bundle
-    my %resourcebundle = ();
+
     foreach my $line (@resourcebundlelines) {
         # Remove any trailing whitespace
@@ -232,10 +268,10 @@
 
                 # Map key to text
-                $resourcebundle{$linekey} = $linetext;
+                $resourcebundle->{$linekey} = $linetext;
             }
         }
     }
 
-    return %resourcebundle;
+    return $resourcebundle;
 }
 
