Re: Language and locale setting in /root/dbootstrap_setting
Petter Reinholdtsen <pere@hungry.com> cum veritate scripsit:
Add something like this:
use_locales_supported () {
case $1 in
en_*) return 0 ;;
whatever_*) return 0 ;;
else_*) return 0 ;;
*)
# the fallback is not to use it.
return 1;
;;
}
and surround the whole thing within
if use_locales_supported $LANG; then
.
.
.
fi
> 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 <pere@hungry.com> 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 <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;
> + }
> +}
> 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 <pere@hungry.com>
> +.SH "SEE ALSO"
> +.LP
> +locale\-gen(8), localedef(1), locale(1), base\-config(8)
>
>
> --
> To UNSUBSCRIBE, email to debian-boot-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
>
--
dancer@debian.org : Junichi Uekawa http://www.netfort.gr.jp/~dancer
GPG Fingerprint : 17D6 120E 4455 1832 9423 7447 3059 BF92 CD37 56F4
Reply to: