Changeset 31419

Show
Ignore:
Timestamp:
16.02.2017 14:34:57 (3 years ago)
Author:
kjdon
Message:

new arg to lookup_string: pass in a 1 if you want the output to be perl internal (unicode-aware) strings, rather than utf8. We want this for eg when we get the 'this document has no text' message, its going into doc_obj which is using perl strings not utf8. Strangely, the few places where we are calling lookup_string for this purpose, it is already passing in an extra 1 arg. do do do do...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone2/perllib/gsprintf.pm

    r27306 r31419  
    3030@gsprintf::ISA=qw(Exporter); 
    3131 
     32use Encode; 
     33 
    3234use unicode; 
    3335use util; 
     
    8789} 
    8890 
     91     
    8992 
    9093sub lookup_string 
    9194{ 
    92     my ($stringkey) = @_; 
     95    my ($stringkey, $native_perl) = @_; 
     96     
     97    if (!defined $native_perl || $native_perl != 1) { 
     98    $native_perl = 0; 
     99    } 
    93100    return "" unless defined $stringkey; 
    94101    # Try the language-specific resource bundle first 
     
    119126    } 
    120127     
    121     # Return the string matching the key 
    122     return $utf8string if (!defined($outputencoding) || $outputstringsinUTF8 
    123                || $outputencoding eq "utf8"); 
    124      
     128    if ($native_perl ==1) { 
     129    # decode the utf8 string to perl internal format 
     130    return decode("utf8", $utf8string); 
     131    } 
     132     
     133    # Return the utf8 string if our output encoding is utf8 
     134    if (!defined($outputencoding) || $outputstringsinUTF8 
     135    || $outputencoding eq "utf8") { 
     136    return $utf8string; 
     137    } 
     138 
    125139    # If an 8-bit output encoding has been defined, encode the string appropriately 
    126140    my $encoded=unicode::unicode2singlebyte(&unicode::utf82unicode($utf8string), $outputencoding);