From 1b844f017bf9e5726ccafcbfdc46708903644211 Mon Sep 17 00:00:00 2001 From: Rafael Garcia-Suarez Date: Thu, 24 Feb 2005 18:38:38 +0000 Subject: 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. --- urpm/msg.pm | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'urpm') 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( -- cgit v1.2.1