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

Re: [locales] Solving the "debconf is not a registry" issue



On Mon, Apr 28, 2003 at 03:55:38AM +0900, GOTO Masanori wrote:
> At Thu, 24 Apr 2003 14:53:49 -0400,
> Joey Hess wrote:
> > [1  <text/plain; us-ascii (quoted-printable)>]
> > GOTO Masanori wrote:
> > > It's fine, and in this modification chance, we would like to apply
> > > #117509 "locales: Message grammar".  Do you think?
> > 
> > Yes, that is a definite improvement.
> 
> Well, Denis, could you send the complete patch including your fix and
> this #117509 improvement?
[...]

Sure, here is an updated patch.
There is an important change, /usr/lib/locale/* is now cleaned up by
locale-gen and not postinst.  The reason is that with this change config
and postinst files do only manage the configuration files, and locale-gen
manages locales into /usr/lib/locale/.  Next improvement will be to
regenerate only the locales whose definition files have changed, and it
will be done by patching locale-gen.

  DEBIAN/templates:
    * Apply patch from #117509 and another typo fix by Joey Hess
    * In locales/locales_to_be_generated, Choices is no more translatable
      because it is set to Choices: ${locales}
  DEBIAN/config:
    * Replace /bin/bash by /bin/sh on the shebang line
    # Add support for backing up
    * Parse configuration files and set debconf values 
  DEBIAN/postinst:
    * Recreate configuration files from debconf values and run locale-gen
    * As explained by Joey Hess, this script should be safer because some
      border cases are now taken into account: configuration files might
      have no EOL at EOF, and line order is preserved.
  usr/sbin/locale-gen:
    * Clean up /usr/lib/locale/ before generating locales

Denis
Index: DEBIAN/templates
===================================================================
RCS file: /cvs/glibc/glibc-package/debian/locales/DEBIAN/templates,v
retrieving revision 1.5
diff -u -r1.5 templates
--- DEBIAN/templates	27 Feb 2003 13:16:16 -0000	1.5
+++ DEBIAN/templates	27 Apr 2003 20:04:39 -0000
@@ -1,24 +1,24 @@
 Template: locales/locales_to_be_generated
 Type: multiselect
-_Choices: Leave alone, ${locales}
+Choices: ${locales}
 _Description: Select locales to be generated.
  Locale is a framework to switch between multiple languages for users who can
  select to use their language, country, characters, collation order, etc.
  .
- You can choose locales to be generated by selecting locales you want.
- Selected locales will be saved to `/etc/locale.gen' file. You can also
- manually edit this file. You need to run `locale-gen' after edit the file.
+ Choose which locales to generate.  The selection will be saved to
+ `/etc/locale.gen', which you can also edit manually (you need to run
+ `locale-gen' afterwards).
 
 Template: locales/default_environment_locale
 Type: select
-_Choices: Leave alone, None, ${locales}
+_Choices: None, ${locales}
 Default: C
 _Description: Which locale should be the default in the system environment?
  Many packages in Debian use locales to display text in the correct
  language for users. The default is C but you can change this if you're not
  a native English speaker.
  .
- Note: This will reflect the language for your whole system. If you're
+ Note: This will select the language for your whole system. If you're
  running a multi-user system where not all of your users speak the language
  of your choice, then they will run into difficulties and you might want to
  leave "C" as the default locale.
Index: usr/sbin/locale-gen
===================================================================
RCS file: /cvs/glibc/glibc-package/debian/locales/usr/sbin/locale-gen,v
retrieving revision 1.4
diff -u -r1.4 locale-gen
--- usr/sbin/locale-gen	25 Mar 2003 11:07:47 -0000	1.4
+++ usr/sbin/locale-gen	27 Apr 2003 20:04:39 -0000
@@ -7,6 +7,10 @@
 
 [ -f $LOCALEGEN -a -s $LOCALEGEN ] || exit 0;
 
+# Remove all old locale dir and locale-archive before generating new
+# locale data.
+rm -rf /usr/lib/locale/* || true
+
 umask 022
 
 echo "Generating locales..."
#!/bin/sh
set -e

. /usr/share/debconf/confmodule
db_version 2.0
db_capb backup multiselect

#   Initializes debconf default values from the ones found in
#   configuration files
if [ -e /etc/locale.gen ]; then
    LG=/etc/locale.gen
    SELECTED_LOCALES=$(sed -e '/^[a-zA-Z]/!d' $LG | tr '\n' ',' | sed -e 's/,/, /g' -e 's/, *$//')
    db_set locales/locales_to_be_generated "${SELECTED_LOCALES}"
else
    LG=/dev/null
fi
if [ -e /etc/environment ]; then
    db_set locales/default_environment_locale $(awk 'BEGIN {lang="None"} /^LANG=/ {gsub("\"", ""); sub("LANG=", ""); lang=$0;} END {print lang}' /etc/environment)
else
    db_set locales/default_environment_locale None
fi

#   Add a newline in case /etc/locale.gen has no trailing newline at EOF
SUPPORTED_LOCALES="
__SUPPORTED_LOCALES__"
SUPPORTED_LOCALES=$( (cat $LG && echo "$SUPPORTED_LOCALES") | sed -e '/^[a-zA-Z]/!d' | sort -u | tr '\n' ',' | sed -e 's/,/, /g' -e 's/, *$//')
db_subst locales/locales_to_be_generated locales "${SUPPORTED_LOCALES}"

STATE=1
while [ "$STATE" -ge 0 ]; do
    case "$STATE" in
    0)
        exit 1
        ;;
    1)
        db_input medium locales/locales_to_be_generated || true
        ;;
    2)
        db_get locales/locales_to_be_generated && DEFAULT_LOCALES=$(echo $RET | sed -e 's/None,*//g' -e 's/ [^ ]*,/,/g' -e 's/ [^ ]*$//')

        if test -z "$DEFAULT_LOCALES"; then
            DEFAULT_LOCALES=C
        else
            DEFAULT_LOCALES="C, $DEFAULT_LOCALES"
        fi
        db_subst locales/default_environment_locale locales $DEFAULT_LOCALES
        db_input medium locales/default_environment_locale || true
        ;;
    *)
        break
        ;;
    esac
    if db_go; then
        STATE=$(($STATE + 1))
    else
        STATE=$(($STATE - 1))
    fi
done
#! /bin/sh
set -e

LG="/etc/locale.gen"
EE="/etc/environment"

if [ "$1" = configure ]; then

    . /usr/share/debconf/confmodule
    db_version 2.0

    db_get locales/locales_to_be_generated && SELECTED_LOCALES=$RET
    db_get locales/default_environment_locale && SELECTED="$RET"

    if [ -n "$SELECTED_LOCALES" ]; then
        if [ -e $LG ]; then
            #   Comment previous defined locales
            sed -e 's/^[a-zA-Z]/#&/' $LG > $LG.tmp || true
            mv -f $LG.tmp $LG
        else
            cat > $LG << EOF
# This file lists locales that you wish to have built. You can find a list
# of valid supported locales at /usr/share/i18n/SUPPORTED. Other
# combinations are possible, but may not be well tested. If you change
# this file, you need to rerun locale-gen.
#

EOF
        fi
        list=`echo $SELECTED_LOCALES | sed -e 's/, /,/g'`
        save_IFS=$IFS
        IFS=,
        for locale in $list; do
            if grep -q "^#$locale *\$" $LG; then
                #   Uncomment previous defined locales
                sed -e "s,#$locale *\$,$locale," $LG > $LG.tmp || true
                mv -f $LG.tmp $LG
            else
                #   Add a newline in case last line does not have one
                echo >> $LG
                #   Consecutive blank lines are replaced by a single line
                cat -s $LG > $LG.tmp
                mv -f $LG.tmp $LG
                #   Add a new locale
                echo $locale >> $LG
            fi
        done
        IFS=$save_IFS
    else
        if [ -e $LG ]; then
            sed -e 's/^[a-zA-Z]/#&/' $LG > $LG.tmp || true
            mv -f $LG.tmp $LG
        fi
    fi
    # Update requested locales.
    /usr/sbin/locale-gen

    # Set default LANG environment variable
    if [ -e $EE ]; then
        sed -e '/^ *LANG=/d' $EE > $EE.tmp || true
    else
        :> $EE.tmp
    fi
    if [ -n "$SELECTED" ] && [ "$SELECTED" != "None" ]; then
        #   Add a newline in case last line does not have one
        echo >> $EE.tmp
        echo "LANG=$SELECTED" >> $EE.tmp
        #   Consecutive blank lines are replaced by a single line
        cat -s $EE.tmp > $EE
    fi
    rm -f $EE.tmp
fi

Reply to: