[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: localising base-config - end game



[Eduard Bloch]
> In generaly the second, but the first is also okay _if_ you run
> dpkg-reconfigure locales somewhere in base-config.

Well, I thing the second is outside the scope of the install system.
I have a new patch which should take care of both.

> Yes. But I still don't see why you need the massive changes in
> dbootstrap if base-config is doing the job.

Perhaps smaller changes are enough.

> This things should not be included into woody. Instead, we create a
> patchset, so CD distributors that want localisation can enable
> it. This means, for special CD distributions, someone can take
> patched BFs, with patched debootstrap (*) and patched base-config.

Well, I believe it is a bug if the first part of the installation uses
one language, and the second part uses English.  And I hope this bug
could be fixed before Woody is released.

> Looks okay in most parts, but locales depends on debconf!

Noted.

Here is a new patch for base-config.  I moved the locale generation
from base-config and into termwrap where I think it belong.

The only thing dbootstrap need to do is to install the required
packages (debconf, locales, jfbterm, fonts?).

Index: termwrap
===================================================================
RCS file: /cvs/debian-boot/base-config/termwrap,v
retrieving revision 1.2
diff -u -3 -p -u -r1.2 termwrap
--- termwrap	2001/05/30 03:40:37	1.2
+++ termwrap	2002/03/09 19:49:38
@@ -15,13 +15,11 @@
 ######################################################################
 ##	Set some environment variables.
 ######################################################################
-# reads /etc/environment.
+# reads /root/dbootstrap_settings (from the boot floppies), and allow
+# overrides in /etc/environment.
+test -f /root/dbootstrap_settings && . /root/dbootstrap_settings
 test -f /etc/environment && . /etc/environment
 
-# Set all locale related environment variables.
-LC_ALL=$LANG
-export LANG LC_ALL
-
 ######################################################################
 ##	Display usage if no argument.
 ######################################################################
@@ -32,6 +30,68 @@ if [ -z "$1" ]; then
 fi
 
 ######################################################################
+##	Generate the locale data files if missing
+######################################################################
+
+# Use LANG_INST and LANGUAGE_INST from /root/dbootstrap_settings if
+# set and allow override with LANG and LANGUAGE from /etc/environemnt.
+
+# Keep the locale info in the _INST variables until they are verified.
+if [ ! -z "$LANG" ]; then
+    LANG_INST=$LANG
+    unset LANG
+fi
+if [ ! -z "$LANGUAGE" ]; then
+    LANGUAGE_INST=$LANGUAGE
+    unset LANGUAGE
+fi
+
+if [ ! -z "$LANG_INST" ]; then
+    # Use this to detect if the 'locales' package is installed
+    localegen=/usr/sbin/locale-gen
+    localeconf=/etc/locale.gen
+    tmpfile=`/bin/tempfile`
+
+    validlocale $LANG_INST 2> /dev/null > $tmpfile || true
+    read locale charset < $tmpfile || true
+    rm -f $tmpfile
+    unset tmpfile
+
+    if validlocale $LANG_INST > /dev/null 2>&1; then
+	# Valid locale, no need to generate it
+	true
+    else
+	# Hm, should we install the 'locales' package if it is missing?
+	if [ -x $localegen ]; then
+	    echo "$locale $charset" >> $localeconf
+	    $localegen || true
+	else
+	    echo "Package 'locales' not installed.  Unable to generate $LANG"
+	fi
+    fi
+
+    # Make sure the locale is valid
+    if validlocale $LANG_INST > /dev/null 2>&1 ; then
+	if [ ! -z "$LANGUAGE_INST" ]; then
+	    LANGUAGE=$LANGUAGE_INST
+	    export LANGUAGE
+	    unset LANGUAGE_INST
+	fi
+	LANG=$LANG_INST
+	LC_ALL=$LANG_INST
+	export LANG LC_ALL
+	unset LANG_INST
+    else
+	unset LANG_INST
+	unset LANGUAGE_INST
+    fi
+    unset locale
+    unset charset
+    unset localeconf
+    unset localegen
+fi
+
+######################################################################
 ##	Recognize terminal type.
 ######################################################################
 case `/usr/bin/tty` in
@@ -70,9 +130,16 @@ esac
 ##	Select suitable terminal as wrapper.
 ######################################################################
 WRAPPER=""
+
+# For this to work, the current locale must be valid.  The block
+# generating the locale should have taken care of that.  If it isn't
+# valid, the output is 'ANSI_X3.4-1968' (at least on my test machine
+# 2002-02-09), and the case test below should unset both LANG and
+# LOCALE
+ENCODING=$(locale charmap)
 
-case $LANG in
-ja*)	
+case $ENCODING in
+eucJP|EUC-JP|ujis)
 	case $TERMINAL in
 	x)
 		#WRAPPER="/usr/X11R6/bin/kterm -e"
@@ -89,6 +156,17 @@ ja*)	
 	# if the terminal can display japanese fonts...
 	esac
 	;;
+ISO-8859-1)
+	# Supported by Linux console and xterm by default?
+	;;
+*)
+
+	# The requested charset is not supported.  Do not use the
+	# given locale.  If it was used, the translated texts might be
+	# completely unreadable in the current terminal
+	echo "Disabling unsupported locale '$LANG' and language list '$LANGUAGE'"
+	unset LANG
+	unset LANGUAGE
 esac
 
 if [ "$1" = "-nnt" ]; then
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/03/09 19:46:45
@@ -1,3 +1,10 @@
+base-config (1.34.1.Skolelinux.1) unstable; urgency=low
+
+  * Added initial locale support.  Generate the locale requested by
+    boot-floppies if the 'locales' package is installed.
+
+ -- Petter Reinholdtsen <pere@hungry.com>  Sun, 24 Feb 2002 17:40:33 +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/03/09 19:46:45
@@ -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/
 
--- /dev/null	Thu Jan  1 01:00:00 1970
+++ lib/35locales	Sat Mar  9 20:34:16 2002
@@ -0,0 +1,13 @@
+#!/bin/sh -e
+#
+# Configure locales if it was installed by debootstrap.
+#
+# This should be executed before the packages are installed, to avoid
+# configuring the locales package twice.
+
+if [ -x /usr/sbin/locale-gen ]; then
+	clear
+	dpkg-reconfigure locales
+	clear
+fi
+
--- /dev/null	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 <pere@hungry.com>
+# 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;
+    }
+}
--- /dev/null	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 <pere@hungry.com>
+.SH "SEE ALSO"
+.LP 
+locale\-gen(8), localedef(1), locale(1), base\-config(8)



Reply to: