[Phil Blundell] > It's fairly easy to go in either direction. There's certainly no need > to pass both of them separately. Either dbootstrap can just write out > /etc/locale.gen itself, in which case base-config just needs to call > locale-gen to do the actual generation, or base-config could generate > the contents of /etc/locale.gen based on $LANG. I don't think it makes > a great deal of difference.
Agreed. I ended up making a patch for base-config trying to generating the needed locale, and unsetting LANG and LANGUAGE if is isn't available. Both LANG and LANGUAGE is needed, to make it possible to use a prioritized list of languages. It is using LANG to determine what to put in /etc/locale.gen. Here is the patch. Should I register it as a bug against base-config? I tested it and using it made dselect show translated text. (tasksel did not find any tasks and aptitide wasn't installed. :-) There is a problem when running base-config using 'script'. I didn't understand what the problem was, but the 'Configuring the base system...'-part of base-config never started. It did run validlocale, but did not seem to run locale-gen. I worked around this problem by setting BASE_CONFIG_IN_SCRIPT=1 manually. Anyway, here is the patch, relative to the current anonymous CVS HEAD version. The two last files (validlocale and validlocale.8) are new. Index: base-config =================================================================== RCS file: /cvs/debian-boot/base-config/base-config,v retrieving revision 1.8 diff -u -3 -p -u -r1.8 base-config --- base-config 2001/11/19 19:32:52 1.8 +++ base-config 2002/02/23 11:47:10 @@ -12,6 +12,37 @@ fi SHELL=/bin/sh export SHELL +# Source it here to set LANG and LANGUAGE, so debconf uses the +# installation language. Make sure LANG is a valid locale and try to +# generate it if it is missing. +if [ -e /root/dbootstrap_settings ]; then + . /root/dbootstrap_settings || true + if [ ! -z "$LANG" ]; then + if LANG=C /usr/sbin/validlocale $LANG > /dev/null 2>&1 ; then + true + else + # Hm, should we make sure locales is installed? + if [ -x /usr/sbin/locale-gen ]; then + LANG=C /usr/sbin/validlocale $LANG \ + >> /etc/locale.gen 2> /dev/null + /usr/sbin/locale-gen || true + else + echo "Package 'locales' not installed." + fi + fi + # Make sure the locale is valid + if LANG=C /usr/sbin/validlocale $LANG > /dev/null 2>&1 ; then + if [ ! -z "$LANGUAGE" ]; then + export LANGUAGE + fi + export LANG + else + unset LANG + unset LANGUAGE + fi + fi +fi + echo "Configuring the base system..." cleanup () { Index: debian/changelog =================================================================== RCS file: /cvs/debian-boot/base-config/debian/changelog,v retrieving revision 1.117 diff -u -3 -p -u -r1.117 changelog --- debian/changelog 2001/12/27 13:27:10 1.117 +++ debian/changelog 2002/02/23 11:47:10 @@ -1,3 +1,9 @@ +base-config (1.34.1) unstable; urgency=low + + * Added locale support. + + -- Petter Reinholdtsen <[EMAIL PROTECTED]> Sat, 23 Feb 2002 12:00:00 +0100 + base-config (1.34) unstable; urgency=low * Added aptitude as an option, and reworked the package selection stage. Index: debian/rules =================================================================== RCS file: /cvs/debian-boot/base-config/debian/rules,v retrieving revision 1.34 diff -u -3 -p -u -r1.34 rules --- debian/rules 2001/10/09 19:24:51 1.34 +++ debian/rules 2002/02/23 11:47:10 @@ -29,7 +29,7 @@ install: build dh_testroot dh_clean -k dh_installdirs usr/share/base-config usr/sbin usr/lib/base-config - install apt-setup tzsetup base-config termwrap debian/base-config/usr/sbin/ + install apt-setup tzsetup base-config termwrap validlocale +debian/base-config/usr/sbin/ install lib/[0-9]* debian/base-config/usr/lib/base-config/ cp Mirrors.masterlist debian/base-config/usr/share/base-config/ Index: validlocale =================================================================== diff -Nur validlocale --- validlocale Thu Jan 1 01:00:00 1970 +++ validlocale Sat Feb 23 11:25:34 2002 @@ -0,0 +1,71 @@ +#!/usr/bin/perl -w +# +# Author: Petter Reinholdtsen <[EMAIL PROTECTED]> +# Date: 2002-02-23 +# +# Test if the locale given as argument is a valid locale. If it +# isn't, print on stdout the string to add to /etc/locale.gen to make +# locale-gen generate the locale (if it exists at all). + +use POSIX qw(setlocale LC_ALL); + +my $debug = 0; + +my $defaultcharset = $ENV{"DEFAULTCHARSET"} || "ISO-8859-1"; + +my $supportedlist = "/usr/share/i18n/SUPPORTED"; + +unless (defined $ARGV[0]) { + usage(); + exit 1; +} + +my $LANG = $ARGV[0]; + +my $loc = setlocale(LC_ALL, $LANG); +if ( ! $loc) { + print STDERR "locale '$LANG' not available\n"; + + my ($locale) = $LANG =~ m/^([^.@]+)/; + my ($charset) = $LANG =~ m/^[^.]+\.([^@]+)/; + my ($modifier) = $LANG =~ m/(@.+)$/; + + $modifier = "" unless defined $modifier; + + # Hm, if charset is missing, how to we pick the correct one to + # use? Fetching the value from /usr/share/i18n/SUPPORTED should + # work on Debian. + $charset = get_default_charset("$locale$modifier") + unless (defined $charset); + + # print "L: $locale C: $charset M: $modifier\n"; + print "$locale$modifier $charset\n"; + + exit 1; +} else { + print STDERR "locale '$LANG' valid and available\n"; + exit 0; +} + +sub usage { + print "Usage: $0 <locale>\n" +} + +sub get_default_charset { + my ($locale) = @_; + my ($l, $c); + open(SUPPORTED, "< $supportedlist") || die "Unable to open $supportedlist";+ +while (<SUPPORTED>) { + chomp; + ($l, $c) = split(/\s+/); + print "Checking '$l' '$c' != '$locale'\n" if $debug; + last if ($l eq $locale); + } + close(SUPPORTED); + + if ($l eq $locale) { + return $c; + } else { + return $defaultcharset; + } +} Index: validlocale.8 =================================================================== diff -Nur ./validlocale.8 --- validlocale.8 Thu Jan 1 01:00:00 1970 +++ validlocale.8 Sat Feb 23 11:54:02 2002 @@ -0,0 +1,49 @@ +.TH "validlocale" "8" "0.1" "Petter Reinholdtsen" "" +.SH "NAME" +.LP +validlocale \- Test if a given locale is available +.SH "SYNTAX" +.LP +validlocale <\fIlocale\fP> +.SH "DESCRIPTION" +.LP +Test if the locale given as argument is a valid locale. If it +isn't, print on stdout the string to add to /etc/locale.gen to make +locale\-gen generate the locale (if it exists at all). +.SH "FILES" +.LP +\fI/usr/sbin/validlocale\fP +.br +\fI/usr/share/i18n/SUPPORTED\fP +.SH "ENVIRONMENT VARIABLES" +.LP +.TP +\fBDEFAULTCHARSET\fP +Which charset to assume if the given locale is missing from the +list of supported locales. +.SH "EXAMPLES" +.LP +If you give a valid locale as parameter, it outputs a string +specifying this on stderr: +.LP +.IP +% validlocale C +.br +locale 'C' valid and available +.LP +When given a invalid (not generated or just nonexistant), it +outputs a string on stderr telling that this is an invalid locale, and a string to +stdout with the string to add to /etc/locale.gen +to have this locale generated: +.LP +.IP +% validlocale de_AU@euro +.br +locale 'de_AT@euro' not available +.br +de_AT@euro ISO\-8859\-15 +.SH "AUTHORS" +.LP +Petter Reinholdtsen <[EMAIL PROTECTED]> +.SH "SEE ALSO" +.LP +locale\-gen(8), localedef(1), locale(1), base\-config(8) -- To UNSUBSCRIBE, email to [EMAIL PROTECTED] with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]