Bug#242006: patch: localize short list of countries (bugfixes)
This is the previous patch with the following bugfixes:
- fix typo asksedshort->askedshort in debian/postinst (Frans Pop)
- escape '$' in debian/postinst (Thiemo Seufer)
- remove sed expression 's/$^$/\n/' which does nothing from mkshort
Index: countrychooser/debian/postinst
===================================================================
--- countrychooser/debian/postinst (revision 13691)
+++ countrychooser/debian/postinst (working copy)
@@ -18,6 +18,7 @@
# This is the iso_3166.tab file location
ISO3166TAB=/usr/share/iso-codes/iso_3166.tab
SUPPORTEDLOCALES=/etc/SUPPORTED-short
+SHORTLISTS=/etc/shortlists
for list in $ISO3166TAB ; do
if [ -f "$list" ]; then
@@ -60,6 +61,33 @@
fi
}
+cat_shortlist() {
+ (out = ""
+ IFS='
+'
+ while read line; do
+ if $(echo "$line" | grep -q "^:$1\$"); then
+ out=1
+ elif $(echo "$line" | grep -q "^:"); then
+ out=""
+ elif [ "$out" ]; then
+ echo "$line"
+ fi
+ done
+ ) < $SHORTLISTS
+}
+
+loccountry2code() {
+ COUNTRYNAME=$(echo "$1" | sed "s/^$INDENT//" | sed 's/\\,/,/g')
+ line=`cat_shortlist $2| grep "$COUNTRYNAME\$"`
+ 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 +125,16 @@
# If present, keep track of charset or modifier we got from languagechooser
EXTRA_LANGUAGECHOOSER=`echo $DEFAULTLOCALE | sed -e 's/^[^.@]*//'`
+FIRST_LANG=$(echo $LANGUAGELIST | sed -e 's/:.*$//')
+
+if grep -q "^:$FIRST_LANG\$" $SHORTLISTS; then
+ use_lang=$FIRST_LANG
+elif grep -q "^:$LANGUAGE\$" $SHORTLISTS; then
+ use_lang=$LANGUAGE
+else
+ use_lang=""
+fi
+
# At this step we should have either xx, or xx_YY in LANGNAME
if [ "$LANGUAGE" != "C" ]; then
STATE=1
@@ -112,35 +150,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 [ "$use_lang" ]; then
+ # Build a short list of supported locales for
+ # the language.
+ OLD_IFS="$IFS"
+ IFS='
+'
+ COUNTRIES=$(cat_shortlist $use_lang | sed -e 's/^.* //');
+ SHORTLIST=""
+ 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
+ askedshort=0
+ fi
fi
;;
2)
db_get $shortlist
if [ "$askedshort" = 1 ] && [ "$RET" != "other" ]; then
- COUNTRYCODE="$(country2code "$RET")" || true
+ COUNTRYCODE="$(loccountry2code "$RET" $use_lang )" || true
if [ -n "$COUNTRYCODE" ]; then
break
fi
Index: countrychooser/debian/rules
===================================================================
--- countrychooser/debian/rules (revision 13691)
+++ countrychooser/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,7 @@
# 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
+ install -m644 debian/short-tmp/shortlists debian/$(PACKAGE)/etc/shortlists
# Build architecture-independent files here.
binary-indep: build install
Index: countrychooser/mkshort
===================================================================
--- countrychooser/mkshort (revision 0)
+++ countrychooser/mkshort (revision 0)
@@ -0,0 +1,56 @@
+#! /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
+
+rm -f debian/short-tmp/*.tab
+rm -f debian/short-tmp/*.short
+
+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/";$//' | awk '/^.+$/{print}'> $tabfile
+ outfile=debian/short-tmp/$lang_variant.short
+ :>$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
+
+# make one file from parts
+
+SHORTLISTS=debian/short-tmp/shortlists
+:>$SHORTLISTS
+
+for file in debian/short-tmp/*.short; do
+ lang=`basename $file .short`
+ echo ":$lang" >> $SHORTLISTS
+ cat $file >> $SHORTLISTS
+done
+
Property changes on: countrychooser/mkshort
___________________________________________________________________
Name: svn:executable
+ *
Reply to: