Ignore:
Timestamp:
2004-03-05T10:52:59+13:00 (20 years ago)
Author:
mdewsnip
Message:

Hopefully the last piece of the multilingual output functionality: uses the output encoding specified in the resource bundle. (Most times the output won't be wanted in UTF-8 -- rather an 8-bit encoding such as ISO 8859-1 suitable for terminals).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/gsdl/perllib/gsprintf.pm

    r6925 r6934  
    2828
    2929
     30use unicode;
    3031use util;
    3132
     
    3334my $loadedlanguage = "<none>";
    3435my %loadedresourcebundle = ();
     36my $outputencoding;
    3537
    3638
     
    5254sub lookup_string
    5355{
    54     local ($stringkey) = @_;
     56    my ($stringkey) = @_;
    5557
    5658    # Load the default resource bundle if one isn't already loaded
     
    5961    }
    6062
    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);
    6372}
    6473
     
    6675sub load_resource_bundle
    6776{
    68     local $language = shift(@_);
     77    my $language = shift(@_);
    6978
    7079    # If the desired resource bundle is the one already loaded, no action is necessary
     
    7483
    7584    # 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);
    7988
    8089    # If the specific resource bundle cannot be opened, use the generic (English) one
     
    8695    }
    8796
    88     local @resourcebundlelines = <RESOURCE_BUNDLE>;
     97    my @resourcebundlelines = <RESOURCE_BUNDLE>;
    8998    close(RESOURCE_BUNDLE);
    9099
     
    100109        # Parse key (everything up to the first colon)
    101110        $line =~ /^([^:]+):(.+)$/;
    102         local $linekey = "{" . $1 . "}";
    103         local $linetext = $2;
     111        my $linekey = "{" . $1 . "}";
     112        my $linetext = $2;
    104113
    105114        # Map key to text
     
    107116    }
    108117    }
     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
     129sub get_output_encoding
     130{
     131    return $outputencoding;
     132}
     133
     134
     135sub set_output_encoding
     136{
     137    $outputencoding = shift(@_);
    109138}
    110139
Note: See TracChangeset for help on using the changeset viewer.