Package: countrychooser
Version: SVN
Severity: normal
Followup-For: Bug #242006

   Attached patch adds localized short list support to countrychooser.
Short lists are generated during package build and stored in
/usr/share/shortnames/.

-- System Information:
Debian Release: testing/unstable
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.4.25
Locale: LANG=uk_UA.UTF-8, LC_CTYPE=uk_UA.UTF-8
Index: debian/postinst
===================================================================
--- debian/postinst     (revision 12984)
+++ debian/postinst     (working copy)
@@ -60,6 +60,17 @@
        fi
 }
 
+loccountry2code() {
+       COUNTRYNAME=$(echo "$1" | sed "s/^$INDENT//" | sed 's/\\,/,/g')
+       line=`grep "$COUNTRYNAME$" $SHORTFILE`
+       if [ -n "$line" ]; then
+               set $line
+               if [ -n "$1" ]; then
+                       echo "$1"
+               fi
+       fi
+}
+
 # First grab back the country we got from languagechooser
 # (or from elsewhere) and populate the debconf database with
 # it so that it becomes the default choice
@@ -97,6 +108,15 @@
 # If present, keep track of charset or modifier we got from languagechooser
 EXTRA_LANGUAGECHOOSER=`echo $DEFAULTLOCALE | sed -e 's/[EMAIL PROTECTED]//'`
 
+FIRST_LANG=$(echo $LANGUAGELIST | sed -e 's/:.*$//')
+SHORTFILE=/usr/share/shortnames/shortnames.$FIRST_LANG
+if [ ! -r $SHORTFILE ]; then
+   SHORTFILE=/usr/share/shortnames/shortnames.$LANGUAGE
+fi
+if [ ! -r $SHORTFILE ]; then
+   SHORTFILE=''
+fi
+
 # At this step we should have either xx, or xx_YY in LANGNAME
 if [ "$LANGUAGE" != "C" ]; then
        STATE=1
@@ -112,35 +132,35 @@
                                askedshort=0
                                fullprio=medium
                        else
-                               # Build a short list of supported locales fo
-                               # the language.
-                               SHORTLIST=''
-                               for code in $(grep -e "^$LANGUAGE" $SUPPORTEDLOCALES | 
cut -b 4-5 | sort | uniq); do
-                                       line=`grep -e "^$code" $ISO3166TAB`
-                                       if [ "$line" ] ; then
-                                               OLD_IFS="$IFS"
-                                               IFS='   '
-                                               set $line
-                                               IFS="$OLD_IFS"
-                                               if [ "$2" ]; then
-                                                       countryname=$(echo 
"${INDENT}$2" | sed 's/,/\\,/g');
-                                               fi
+                               if [ "$SHORTFILE" ]; then
+                                       # Build a short list of supported locales fo
+                                       # the language.
+                                       OLD_IFS="$IFS"
+                                       IFS='
+'
+                                       
+                                       COUNTRIES=$(cat $SHORTFILE | sed -e 's/^.*     
 //');
+                                       for name in $COUNTRIES; do
                                                if [ ! -z "${SHORTLIST}" ]; then
                                                        SHORTLIST="${SHORTLIST}, "
                                                fi
+                                               countryname=$(echo "${INDENT}${name}" 
| sed -e 's/,/\\,/')
                                                SHORTLIST="${SHORTLIST}${countryname}"
-                                       fi
-                               done
-                               db_subst $shortlist SHORTLIST "${SHORTLIST}"
-                               db_subst $shortlist DEFAULTLOCALE "${DEFAULTLOCALE}"
-                               db_input critical $shortlist || [ $? -eq 30 ]
-                               askedshort=1
+                                       done
+                                       IFS="$OLD_IFS"  
+                                       db_subst $shortlist SHORTLIST "${SHORTLIST}"
+                                       db_subst $shortlist DEFAULTLOCALE 
"${DEFAULTLOCALE}"
+                                       db_input critical $shortlist || [ $? -eq 30 ]
+                                       askedshort=1
+                               else
+                                       asksedshort=0
+                               fi
                        fi
                ;;
                2)
                        db_get $shortlist
                        if [ "$askedshort" = 1 ] && [ "$RET" != "other" ]; then
-                               COUNTRYCODE="$(country2code "$RET")" || true
+                               COUNTRYCODE="$(loccountry2code "$RET")" || true
                                if [ -n "$COUNTRYCODE" ]; then
                                        break
                                fi
Index: debian/rules
===================================================================
--- debian/rules        (revision 12984)
+++ debian/rules        (working copy)
@@ -16,13 +16,14 @@
        ./get-SUPPORTED
        # Build the templates
        ./mktemplates
+       ./mkshort
        touch build-stamp
 
 clean:
        dh_testdir
        dh_testroot
        rm -f build-stamp
-       rm -rf debian/pobuild debian/iso-codes
+       rm -rf debian/pobuild debian/iso-codes debian/short-tmp
        dh_clean debian/templates.tmp debian/templates debian/SUPPORTED-short
 
 install: build
@@ -33,6 +34,10 @@
        # The following while we have no other way to get SUPPORTED
        # Should become useless when we will have it
        install -m644 debian/SUPPORTED-short debian/$(PACKAGE)/etc/SUPPORTED-short
+       dh_installdirs usr/share/shortnames
+       for name in debian/short-tmp/shortnames.*; do \
+          install -m644 $$name debian/$(PACKAGE)/usr/share/shortnames; \
+       done
 
 # Build architecture-independent files here.
 binary-indep: build install
Index: mkshort
===================================================================
--- mkshort     (revision 0)
+++ mkshort     (revision 0)
@@ -0,0 +1,41 @@
+#! /bin/sh
+
+set -e
+
+ISO3166TAB=/usr/share/iso-codes/iso_3166.tab
+SUPPORTED=/usr/share/i18n/SUPPORTED
+
+if [ ! -d debian/short-tmp ]; then
+   mkdir debian/short-tmp
+fi
+
+for file in debian/po/*.po en.po; do
+  lang_variant=`basename $file .po`
+  lang=$(echo "$lang_variant" | sed -e 's/_.*$//')
+  tabfile=debian/short-tmp/$lang_variant.tab
+  # create TAB file for this language
+  msgconv debian/iso-codes/$lang_variant.po -t UTF-8 --stringtable-output | tail -n 
+3 |
+    sed -e 's/" = "/   /' -e 's/^"//' -e 's/";$//' -e 's/$^$/\n/' | awk 
'/^.+$/{print}'> $tabfile
+  outfile=debian/short-tmp/shortnames.$lang_variant
+  :>$outfile
+  (for code in $(grep -e "^$lang" $SUPPORTED | cut -b 4-5 | sort | uniq); do
+      line=`grep -e "^$code" $ISO3166TAB`
+      if [ "$line" ]; then
+         OLD_IFS="$IFS"
+        IFS='  '
+        set $line
+        IFS="$OLD_IFS"
+        if [ "$2" ]; then
+          translation=$(grep "^$2      " $tabfile| sed -e 's/^.*       //')
+          if [ "$translation" ]; then
+             echo "$1  $translation" >> $outfile
+          else
+             echo "$1  $2" >> $outfile
+          fi
+        fi
+      fi
+   done)
+   if [ $(wc -l < $outfile) -le 1 ]; then
+      rm -f $outfile
+   fi
+done

Property changes on: mkshort
___________________________________________________________________
Name: svn:executable
   + *

Reply via email to