Package: debconf
Version: 1.5.20
Severity: important
Tags: patch

NOTE: there is one issue with the proposed patch; see below!

One issue with debconf is that it will display the "code" values from a 
Choices-C field instead of the descriptive values from the default Choices 
field.
With the increased usage of Choices-C (e.g. in ucf), this is a real problem 
as the "code" values are generally just not descriptive enough.

With current debconf (with 'test' being a script that shows a template using 
Choices-C):
# LC_ALL=C ./test
# LANG=C ./test
# LANGUAGE=C ./test
# LANG=nl ./test # invalid
# LC_ALL=<anything invalid> ./test
=> Choices are the values from Choices-C!

Second issue is that LANGUAGE=en is not respected:
# LANG= LANGUAGE=en LC_ALL=nl_NL.UTF-8 ../../test
=> Dialog is displayed in Dutch
@langs = en:nl_nl.utf-8:nl_nl:nl.utf-8:nl

A more extensive description of these issues and a test case can be found in 
this thread: http://lists.debian.org/debian-boot/2008/04/msg00019.html.

Attached a patch that solves these two issues.

Note that this patch effectively obsoletes the use of *-C fields as
"translation" values to be used with the C locale or if i18n is disabled.
I doubt this is used (much) currently and I can also not really see a 
use-case for it.
If there is some reason this is undesired, the only alternative solution 
would seem to be to start a transition from Choices-C to a new special 
field, for example Choices-Coded.

The patch also adds a debugging option: by setting DEBCONF_C_VALUES=true, a 
developer can make debconf display the values from Choices-C.

I had one problem while implementing this new option, which is why one line 
in the patch is commented out in Debconf/Template.pm _getlangs():
        #push (@langs, 'c') if Debconf::Config->c_values eq 'true';

If I uncomment this, I get
   Can't locate object method "c_values" via package "Debconf::Config"
   at /usr/share/perl5/Debconf/Template.pm line 277.
even though Debconf::Config has been loaded and the other use of the same 
value works without problems.
I have tried a lot of things to solve that, but had to admit defeat. I hope 
that a real perl coder will be able to solve this issue.

Cheers,
FJP

diff --git a/Debconf/Config.pm b/Debconf/Config.pm
index df2d571..feacb27 100644
--- a/Debconf/Config.pm
+++ b/Debconf/Config.pm
@@ -16,7 +16,7 @@ use Debconf::Db;
 
 use fields qw(config templates frontend frontend_forced priority terse reshow
               admin_email log debug nowarnings smileys sigils
-              noninteractive_seen);
+              noninteractive_seen c_values);
 our $config=fields::new('Debconf::Config');
 
 our @config_files=("/etc/debconf.conf", "/usr/share/debconf/debconf.conf");
@@ -394,6 +394,20 @@ sub noninteractive_seen {
 	return 'false';
 }
 
+=item c_values
+
+Set to true to display "coded" values from Choices-C fields instead of the
+descriptive values from other fields for select and multiselect templates.
+
+=cut
+
+sub c_values {
+	my $class=shift;
+	return $ENV{DEBCONF_C_VALUES} if exists $ENV{DEBCONF_C_VALUES};
+	return $config->{c_values} if exists $config->{c_values};
+	return 'false';
+}
+
 =back
 
 =head1 FIELDS
diff --git a/Debconf/Template.pm b/Debconf/Template.pm
index 1657258..e365e49 100644
--- a/Debconf/Template.pm
+++ b/Debconf/Template.pm
@@ -19,6 +19,8 @@ use Debconf::Question;
 use fields qw(template);
 use Debconf::Log q{:all};
 use Debconf::Encoding;
+use Debconf::Config;
+
 
 # Class data
 our %template;
@@ -409,6 +411,10 @@ sub _getlangs {
 	# hits testing, and I will need to (pre?)depend on it then.
 	my $language=setlocale(5); # LC_MESSAGES
 	my @langs = ();
+
+	# Make sure C is the first in the list if DEBCONF_C_VALUES is set
+	#push (@langs, 'c') if Debconf::Config->c_values eq 'true';
+
 	# LANGUAGE has a higher precedence than LC_MESSAGES
 	if (exists $ENV{LANGUAGE} && $ENV{LANGUAGE} ne '') {
 		foreach (split(/:/, $ENV{LANGUAGE})) {
@@ -437,6 +443,13 @@ sub AUTOLOAD {
 		if ($Debconf::Template::i18n && @langs) {
 			my @fields = grep /^\Q$field\E(?:[EMAIL PROTECTED]|$)/, $Debconf::Db::templates->fields($this->{template});
 			foreach my $lang (@langs) {
+				# Avoid displaying Choices-C values
+				# (unless requested)
+				if ($lang eq 'c' &&
+				    Debconf::Config->c_values ne 'true') {
+					$lang="en";
+				}
+
 				# First check for a field that matches the
 				# language and the encoding. No charset
 				# conversion is needed. This also takes care
@@ -456,11 +469,11 @@ sub AUTOLOAD {
 						}
 					}
 				}
+
+				# For en and c, force default template
+				# if no specific template was found
+				last if ($lang eq 'en' || $lang eq 'c');
 			}
-		} elsif (not $Debconf::Template::i18n && $field !~ /-c$/i) {
-			# If i18n is turned off, try *-C first.
-			$ret=$Debconf::Db::templates->getfield($this->{template}, $field.'-c');
-			return $ret if defined $ret;
 		}
 
 		$ret=$Debconf::Db::templates->getfield($this->{template}, $field);
diff --git a/debian/changelog b/debian/changelog
index c34223f..e8fb1d3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+debconf (1.5.21~fjp) UNRELEASED; urgency=low
+
+  * Better language handling.
+
+ -- Frans Pop <[EMAIL PROTECTED]>  Sat, 19 Apr 2008 15:33:39 +0200
+
 debconf (1.5.20) unstable; urgency=low
 
   * Use signal names rather than numbers in debconf-apt-progress.
diff --git a/doc/man/debconf-devel.7 b/doc/man/debconf-devel.7
index 08aa804..dfe26f1 100644
--- a/doc/man/debconf-devel.7
+++ b/doc/man/debconf-devel.7
@@ -584,6 +584,13 @@ It's rather useful to use debconf's readline frontend when you're debugging
 the debugging output is easily preserved and logged.
 .RE
 .TP
+.B DEBCONF_C_VALUES
+.RS
+If this environment variable is set to 'true', the frontend will display
+the values in Choices-C field (if present) of select and multiselect
+templates rather than the descriptive values.
+.RE
+.TP
 .B debconf-communicate
 Another useful tool is the
 .BR debconf-communicate (1)

Attachment: signature.asc
Description: This is a digitally signed message part.

Reply via email to