summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2005-02-24 18:38:38 +0000
committerRafael Garcia-Suarez <rgarciasuarez@mandriva.org>2005-02-24 18:38:38 +0000
commit1b844f017bf9e5726ccafcbfdc46708903644211 (patch)
tree9df8f0bf9b5ca265b89ab107e76d0026c363bca0
parent2dbadc62734d00c9e0ed360e259cf2414c42145c (diff)
downloadurpmi-1b844f017bf9e5726ccafcbfdc46708903644211.tar
urpmi-1b844f017bf9e5726ccafcbfdc46708903644211.tar.gz
urpmi-1b844f017bf9e5726ccafcbfdc46708903644211.tar.bz2
urpmi-1b844f017bf9e5726ccafcbfdc46708903644211.tar.xz
urpmi-1b844f017bf9e5726ccafcbfdc46708903644211.zip
Adds a function from_utf8() to convert strings from RPM headers (utf8)
to the encoding of the current locale. With a placeholder if I18N::Langinfo is not available.
-rw-r--r--urpm/msg.pm14
1 files changed, 13 insertions, 1 deletions
diff --git a/urpm/msg.pm b/urpm/msg.pm
index 00dc5b75..151f016b 100644
--- a/urpm/msg.pm
+++ b/urpm/msg.pm
@@ -3,7 +3,7 @@ package urpm::msg;
use strict;
use Exporter;
our @ISA = 'Exporter';
-our @EXPORT = qw(N log_it to_utf8 message_input message toMb);
+our @EXPORT = qw(N log_it to_utf8 message_input message toMb from_utf8);
#- I18N.
eval {
@@ -13,6 +13,18 @@ eval {
Locale::gettext::textdomain("urpmi");
};
+my $codeset; #- encoding of the current locale
+eval {
+ require I18N::Langinfo;
+ I18N::Langinfo->import(qw(langinfo CODESET));
+ $codeset = langinfo(CODESET()); # note the ()
+};
+
+sub from_utf8_full { Locale::gettext::iconv($_[0], "UTF-8", $codeset) }
+sub from_utf8_dummy { $_[0] }
+
+*from_utf8 = defined $codeset ? *from_utf8_full : *from_utf8_dummy;
+
sub N {
my ($format, @params) = @_;
sprintf(