Index: languagelist
===================================================================
--- languagelist	(revision 46988)
+++ languagelist	(working copy)
@@ -1,92 +1,92 @@
 #
 # This is the complete list of languages (locales) to choose from.
-# Language;supported_environments;langcode;countrycode;fallbacklocale;langlist;console-data
-Albanian;2;sq;AL;sq_AL.UTF-8;;kbd=lat0-sun16(utf8)
-Arabic;3;ar;EG;ar_EG.UTF-8;;
-#X Armenian;4;hy;AM;hy_AM;;
-Basque;1;eu;ES;eu_ES.UTF-8;;kbd=lat0-sun16(utf8)
-Belarusian;2;be;BY;be_BY.UTF-8;;cyr
-Bengali;4;bn;BD;bn_BD;;
-Bosnian;2;bs;BA;bs_BA.UTF-8;;kbd=Lat2-Terminus16(utf8)
-Bulgarian;2;bg;BG;bg_BG;;kbd=ruscii_8x16(cp1251)
+# Language;supported_environments;langcode;countrycode;fallbacklocale;encoding;langlist;console-data
+Albanian;2;sq;AL;sq_AL.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Arabic;3;ar;EG;ar_EG.UTF-8;UTF-8;;
+#X Armenian;4;hy;AM;hy_AM;UTF-8;;
+Basque;1;eu;ES;eu_ES.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Belarusian;2;be;BY;be_BY.UTF-8;UTF-8;;cyr
+Bengali;4;bn;BD;bn_BD;UTF-8;;
+Bosnian;2;bs;BA;bs_BA.UTF-8;UTF-8;;kbd=Lat2-Terminus16(utf8)
+Bulgarian;2;bg;BG;bg_BG;CP1251;;kbd=ruscii_8x16(cp1251)
 # For C locale, set language to 'en' to make sure questions are "translated"
 # to English instead of showing codes.
 C;0;en;;C;
-Catalan;1;ca;ES;ca_ES.UTF-8;;kbd=lat0-sun16(utf8)
+Catalan;1;ca;ES;ca_ES.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
 # Special case for Chinese as the two flavours share the same ISO 639 code
 # Both will trigger countrychooser. Each will be the backup for the other
 # one
-Chinese (Simplified);3;zh;CN;zh_CN.UTF-8;zh_CN:zh;
-Chinese (Traditional);3;zh;TW;zh_TW.UTF-8;zh_TW:zh;
-Croatian;2;hr;HR;hr_HR.UTF-8;;kbd=lat2-sun16(utf8)
-Czech;2;cs;CZ;cs_CZ.UTF-8;;kbd=lat2-sun16(utf8)
-Danish;1;da;DK;da_DK.UTF-8;;kbd=lat0-sun16(utf8)
-Dutch;1;nl;NL;nl_NL.UTF-8;;kbd=lat0-sun16(utf8)
-Dzongkha;4;dz;BT;dz_BT;;
-English;0;en;US;en_US.UTF-8;;kbd=lat0-sun16(utf8)
+Chinese (Simplified);3;zh;CN;zh_CN.UTF-8;UTF-8;zh_CN:zh;
+Chinese (Traditional);3;zh;TW;zh_TW.UTF-8;UTF-8;zh_TW:zh;
+Croatian;2;hr;HR;hr_HR.UTF-8;UTF-8;;kbd=lat2-sun16(utf8)
+Czech;2;cs;CZ;cs_CZ.UTF-8;UTF-8;;kbd=lat2-sun16(utf8)
+Danish;1;da;DK;da_DK.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Dutch;1;nl;NL;nl_NL.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Dzongkha;4;dz;BT;dz_BT;UTF-8;;
+English;0;en;US;en_US.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
 # The Esperanto locale *is* (or will be as of 1/11/2006) eo.UTF-8
 # so no country on purpose. The default country is Antarctica because...
 # ...why not..:-)
-Esperanto;2;eo;AQ;eo;;kbd=LatArCyrHeb-16(utf8)
-Estonian;2;et;EE;et_EE.UTF-8;;kbd=lat0-sun16(utf8)
-Finnish;1;fi;FI;fi_FI.UTF-8;;kbd=lat0-sun16(utf8)
-French;1;fr;FR;fr_FR.UTF-8;;kbd=lat9u-16(utf8)
-Galician;1;gl;ES;gl_ES.UTF-8;;kbd=lat0-sun16(utf8)
-Georgian;4;ka;GE;ka_GE;;kbd=ka8x16thin(utf8)
-German;1;de;DE;de_DE.UTF-8;;kbd=lat0-sun16(utf8)
-Greek;2;el;GR;el_GR.UTF-8;;kbd=iso07.f16(utf8)
-Gujarati;4;gu;IN;gu_IN;;
-Hebrew;3;he;IL;he_IL.UTF-8;;kbd=LatArCyrHeb-16(utf8)
-Hindi;4;hi;IN;hi_IN;;
-Hungarian;2;hu;HU;hu_HU.UTF-8;;kbd=lat2-sun16(utf8)
-#X Icelandic;1;is;IS;is_IS.UTF-8;;kbd=lat9u-16(utf8)
-Indonesian;1;id;ID;id_ID.UTF-8;;kbd=lat0-sun16(utf8)
-#X Irish;1;ga;IE;ga_IE.UTF-8;;kbd=lat0-sun16(utf8)
-Italian;1;it;IT;it_IT.UTF-8;;kbd=lat0-sun16(utf8)
-Japanese;3;ja;JP;ja_JP.UTF-8;;
-#X Kannada;4;kn;IN;kn_IN;;
-#X Kazakh;2;kk;KZ;kk_KZ;;kbd=ruscii_8x16(koi8-r)
-Khmer;4;km;KH;km_KH;;
-Korean;3;ko;KR;ko_KR.UTF-8;;
-Kurdish;2;ku;TR;ku_TR.UTF-8;;kbd=Lat15-Terminus16(utf8)
-#X Lao;4;lo;LA;lo_LA;;
-Latvian;2;lv;LV;lv_LV.UTF-8;;kbd=lat7-14(utf8)
-Lithuanian;2;lt;LT;lt_LT.UTF-8;;kbd=LatArCyrHeb-16(utf8)
-#X Malagasy;1;mg;MG;mg_MG.UTF-8;mg_MG:fr_FR:fr:en;kbd=lat0-sun16(utf8)
-#X Malay;1;ms;MY;ms_MY.UTF-8;;kbd=lat0-sun16(utf8)
-Malayalam;4;ml;IN;ml_IN;;
-#X Marathi;4;mr;IN;mr_IN;;
-Macedonian;2;mk;MK;mk_MK.UTF-8;;kbd=iso05.f16(utf8)
-Nepali;4;ne;NP;ne_NP;;
+Esperanto;2;eo;AQ;eo;UTF-8;;kbd=LatArCyrHeb-16(utf8)
+Estonian;2;et;EE;et_EE.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Finnish;1;fi;FI;fi_FI.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+French;1;fr;FR;fr_FR.UTF-8;UTF-8;;kbd=lat9u-16(utf8)
+Galician;1;gl;ES;gl_ES.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Georgian;4;ka;GE;ka_GE.UTF-8;UTF-8;;kbd=ka8x16thin(utf8)
+German;1;de;DE;de_DE.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Greek;2;el;GR;el_GR.UTF-8;UTF-8;;kbd=iso07.f16(utf8)
+Gujarati;4;gu;IN;gu_IN;UTF-8;;
+Hebrew;3;he;IL;he_IL.UTF-8;UTF-8;;kbd=LatArCyrHeb-16(utf8)
+Hindi;4;hi;IN;hi_IN;UTF-8;;
+Hungarian;2;hu;HU;hu_HU.UTF-8;UTF-8;;kbd=lat2-sun16(utf8)
+#X Icelandic;1;is;IS;is_IS.UTF-8;UTF-8;;kbd=lat9u-16(utf8)
+Indonesian;1;id;ID;id_ID.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+#X Irish;1;ga;IE;ga_IE.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Italian;1;it;IT;it_IT.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Japanese;3;ja;JP;ja_JP.UTF-8;UTF-8;;
+#X Kannada;4;kn;IN;kn_IN;UTF-8;;
+#X Kazakh;2;kk;KZ;kk_KZ;PT154;;kbd=ruscii_8x16(koi8-r)
+Khmer;4;km;KH;km_KH;UTF-8;;
+Korean;3;ko;KR;ko_KR.UTF-8;UTF-8;;
+Kurdish;2;ku;TR;ku_TR.UTF-8;UTF-8;;kbd=Lat15-Terminus16(utf8)
+#X Lao;4;lo;LA;lo_LA;UTF-8;;
+Latvian;2;lv;LV;lv_LV.UTF-8;UTF-8;;kbd=lat7-14(utf8)
+Lithuanian;2;lt;LT;lt_LT.UTF-8;UTF-8;;kbd=LatArCyrHeb-16(utf8)
+#X Malagasy;1;mg;MG;mg_MG.UTF-8;UTF-8;mg_MG:fr_FR:fr:en;kbd=lat0-sun16(utf8)
+#X Malay;1;ms;MY;ms_MY.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Malayalam;4;ml;IN;ml_IN;UTF-8;;
+#X Marathi;4;mr;IN;mr_IN;UTF-8;;
+Macedonian;2;mk;MK;mk_MK.UTF-8;UTF-8;;kbd=iso05.f16(utf8)
+Nepali;4;ne;NP;ne_NP;UTF-8;;
 # The Sami translation is really incomplete. We however keep Sami on request
 # of Skolelinux as a kind of reward to them..:-). They need to be able to 
 # choose Sami as an option so that the Sami locale is set as default
-Northern Sami;1;se;NO;se_NO.UTF-8;se_NO:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en;kbd=lat0-sun(utf8)
-Norwegian Bokmaal;1;nb;NO;nb_NO.UTF-8;nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en;kbd=lat0-sun16(utf8)
-Norwegian Nynorsk;1;nn;NO;nn_NO.UTF-8;nn_NO:nn:no_NO:no:nb_NO:nb:da:sv:en;kbd=lat0-sun16(utf8)
-#X Persian;3;fa;IR;fa_IR;;kbd=iso06.f16(utf8)
-Polish;2;pl;PL;pl_PL.UTF-8;;kbd=lat2-sun16(utf8)
-Portuguese;1;pt;PT;pt_PT.UTF-8;pt:pt_BR:en;kbd=lat0-sun16(utf8)
-Portuguese (Brazil);1;pt;BR;pt_BR.UTF-8;pt_BR:pt:en;kbd=lat1-16(utf8)
-Punjabi (Gurmukhi);4;pa;IN;pa_IN;;
-Romanian;2;ro;RO;ro_RO.UTF-8;;kbd=Lat2-Terminus16(utf8)
-Russian;2;ru;RU;ru_RU.UTF-8;;cyr
-#X Sanskrit;4;sa;IN;sa_IN;;
+Northern Sami;1;se;NO;se_NO;UTF-8;se_NO:nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en;kbd=lat0-sun(utf8)
+Norwegian Bokmaal;1;nb;NO;nb_NO.UTF-8;UTF-8;nb_NO:nb:no_NO:no:nn_NO:nn:da:sv:en;kbd=lat0-sun16(utf8)
+Norwegian Nynorsk;1;nn;NO;nn_NO.UTF-8;UTF-8;nn_NO:nn:no_NO:no:nb_NO:nb:da:sv:en;kbd=lat0-sun16(utf8)
+#X Persian;3;fa;IR;fa_IR;UTF-8;;kbd=iso06.f16(utf8)
+Polish;2;pl;PL;pl_PL.UTF-8;UTF-8;;kbd=lat2-sun16(utf8)
+Portuguese;1;pt;PT;pt_PT.UTF-8;UTF-8;pt:pt_BR:en;kbd=lat0-sun16(utf8)
+Portuguese (Brazil);1;pt;BR;pt_BR.UTF-8;UTF-8;pt_BR:pt:en;kbd=lat1-16(utf8)
+Punjabi (Gurmukhi);4;pa;IN;pa_IN;UTF-8;;
+Romanian;2;ro;RO;ro_RO.UTF-8;UTF-8;;kbd=Lat2-Terminus16(utf8)
+Russian;2;ru;RU;ru_RU.UTF-8;UTF-8;;cyr
+#X Sanskrit;4;sa;IN;sa_IN;UTF-8;;
 # Serbian commented for consistency: too incomplete
-#X Serbian;2;sr;CS;sr_YU.UTF-8@cyrillic;;kbd=iso05.f16(utf8)
-Slovak;2;sk;SK;sk_SK.UTF-8;;kbd=lat2-sun16(utf8)
-Slovenian;2;sl;SI;sl_SI.UTF-8;;kbd=lat2-sun16(utf8)
-Spanish;1;es;ES;es_ES.UTF-8;;kbd=lat0-sun16(utf8)
-Swedish;1;sv;SE;sv_SE.UTF-8;;kbd=lat0-sun16(utf8)
-Tagalog;1;tl;PH;tl_PH.UTF-8;;kbd=lat0-sun16(utf8)
-Tamil;4;ta;IN;ta_IN;;
-#X Telugu;4;te;IN;te_IN;;
-Thai;4;th;TH;th_TH.UTF-8;;
-Turkish;2;tr;TR;tr_TR.UTF-8;;kbd=Lat15-Terminus16(utf8)
-Ukrainian;2;uk;UA;uk_UA.UTF-8;;kbd=ruscii_8x16(utf8)
-#X Urdu;3;ur;PK;ur_PK.UTF-8;;
-#X Valencian-Catalan;1;ca@valencia;ES;ca_ES.UTF-8@valencia;;kbd=lat0-sun16(utf8)
-Vietnamese;3;vi;VN;vi_VN.UTF-8;;
-#X Welsh;2;cy;GB;cy_GB.UTF-8;;kbd=iso14.f16(utf8)
-Wolof;2;wo;SN;wo_SN;wo:fr:en;
-#X Xhosa;2;xh;ZA;xh_ZA.UTF-8;;kbd=lat0-sun16(utf8)
+#X Serbian;2;sr;CS;sr_YU.UTF-8@cyrillic;UTF-8;;kbd=iso05.f16(utf8)
+Slovak;2;sk;SK;sk_SK.UTF-8;UTF-8;;kbd=lat2-sun16(utf8)
+Slovenian;2;sl;SI;sl_SI.UTF-8;UTF-8;;kbd=lat2-sun16(utf8)
+Spanish;1;es;ES;es_ES.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Swedish;1;sv;SE;sv_SE.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Tagalog;1;tl;PH;tl_PH.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
+Tamil;4;ta;IN;ta_IN;UTF-8;;
+#X Telugu;4;te;IN;te_IN;UTF-8;;
+Thai;4;th;TH;th_TH.UTF-8;UTF-8;;
+Turkish;2;tr;TR;tr_TR.UTF-8;UTF-8;;kbd=Lat15-Terminus16(utf8)
+Ukrainian;2;uk;UA;uk_UA.UTF-8;UTF-8;;kbd=ruscii_8x16(utf8)
+#X Urdu;3;ur;PK;ur_PK;UTF-8;;
+#X Valencian-Catalan;1;ca@valencia;ES;ca_ES.UTF-8@valencia;UTF-8;;kbd=lat0-sun16(utf8)
+Vietnamese;3;vi;VN;vi_VN;UTF-8;;
+#X Welsh;2;cy;GB;cy_GB.UTF-8;UTF-8;;kbd=iso14.f16(utf8)
+Wolof;2;wo;SN;wo_SN;UTF-8;wo:fr:en;
+#X Xhosa;2;xh;ZA;xh_ZA.UTF-8;UTF-8;;kbd=lat0-sun16(utf8)
Index: languagemap
===================================================================
--- languagemap	(revision 46988)
+++ languagemap	(working copy)
@@ -28,8 +28,9 @@
 	if [ "$3" ] ; then LANGUAGE="$3" ; fi
 	if [ "$4" ] ; then COUNTRY="$4" ; fi
 	if [ "$5" ] ; then FALLBACKLOCALE="$5" ; LOCALE="$5" ; fi
-	if [ "$6" ] ; then LANGUAGELIST="$6"; fi
-	if [ "$7" ] ; then CONSOLE="$7"; fi
+	if [ "$6" ] ; then ENCODING="$6"; fi
+	if [ "$7" ] ; then LANGUAGELIST="$7"; fi
+	if [ "$8" ] ; then CONSOLE="$8"; fi
 
 	if [ -z "$LANGUAGELIST" ] ; then
 		LANGUAGELIST="$LANGUAGE"
@@ -41,4 +42,5 @@
 	LANGUAGE=""
 	LOCALE=C
 	COUNTRY=US
+	ENCODING=""
 fi
Index: debian/rules
===================================================================
--- debian/rules	(revision 46988)
+++ debian/rules	(working copy)
@@ -5,7 +5,7 @@
 build: build-stamp
 build-stamp:
 	dh_testdir
-	chmod u+x ./get-SUPPORTED ./mktemplates.country ./get-iso-codes ./mk_shortlist_templates
+	chmod u+x ./mktemplates.country ./get-iso-codes ./mk_shortlist_templates
 	$(MAKE)
 	touch build-stamp
 
@@ -14,7 +14,7 @@
 	dh_testroot
 	rm -f build-stamp
 	$(MAKE) clean
-	rm -rf debian/pobuild debian/iso-codes debian/short-tmp debian/locales debian/SUPPORTED-short
+	rm -rf debian/pobuild debian/iso-codes debian/short-tmp debian/locales
 	dh_clean
 
 install: build
@@ -31,7 +31,7 @@
 	dh_installdirs etc
 	# 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 /usr/share/i18n/SUPPORTED debian/$(PACKAGE)/usr/share/localechooser/SUPPORTED
 	install -m644 debian/short-tmp/shortlists debian/$(PACKAGE)/etc/shortlists
 
 binary-indep: build install
Index: localechooser
===================================================================
--- localechooser	(revision 46988)
+++ localechooser	(working copy)
@@ -20,10 +20,16 @@
 
 # This is the iso_3166.tab file location
 ISO3166TAB=/usr/share/iso-codes/iso_3166.tab
-SUPPORTEDLOCALES=/etc/SUPPORTED-short
+SUPPORTEDLOCALES=/usr/share/localechooser/SUPPORTED
+if [ ! -f "$SUPPORTEDLOCALES" ]; then
+	SUPPORTEDLOCALES=/usr/share/i18n/SUPPORTED
+fi
 SHORTLISTS=/etc/shortlists
 LANGUAGELISTFILE=/usr/share/localechooser/languagelist
 
+NL='
+'
+
 error() {
 	logger -t localechooser "error: $@"
 	exit 1
@@ -122,6 +128,28 @@
 	fi
 }
 
+# Find the preferred locale given language, country, and encoding.
+preferred_locale() {
+	OLDIFS="$IFS"
+	IFS="$NL"
+	# Look for locales with the right encoding first.
+	for trylocale in $(grep "^$1_$2" $SUPPORTEDLOCALES || true); do
+		IFS="$OLDIFS"
+		if [ -z "$3" ] || [ "${trylocale#* }" = "$3" ]; then
+			echo "${trylocale% *}"
+			return
+		fi
+		IFS="$NL"
+	done
+	# Pick the first of any other available locales.
+	for trylocale in $(grep "^$1_$2" $SUPPORTEDLOCALES || true); do
+		IFS="$OLDIFS"
+		echo "${trylocale% *}"
+		return
+	done
+	IFS="$OLDIFS"
+}
+
 do_preseed() {
 	LOCALE="$1"
 	log "Locale has been preseeded to $LOCALE"
@@ -153,7 +181,7 @@
 				db_fset $shortlist-$SL seen $seenflag || true
 			fi
 			db_fset $fulllist seen $seenflag || true
-			if grep -q "^$LOCALE$" $SUPPORTEDLOCALES ; then
+			if grep -q "^$LOCALE " $SUPPORTEDLOCALES ; then
 				db_set $localecode $LOCALE
 				db_fset $localecode seen $seenflag || true
 				log "Set $localecode = '$LOCALE'"
@@ -327,8 +355,6 @@
 # Keep track of values we have after language selection step
 LOCALE_LANGUAGECHOOSER=$LOCALE
 LANGUAGECODE_LANGUAGECHOOSER=$LANGUAGE
-# If present, keep track of charset or modifier we got previously
-EXTRA_LANGUAGECHOOSER=`echo $FALLBACKLOCALE | sed -e 's/^[^.@]*//'`
 
 FIRST_LANG="${LANGUAGELIST%%:*}"
 
@@ -435,39 +461,36 @@
 
 	db_get $localecode
 	if [ -z "$LOG" -o -z "$RET" ] ; then
-		for entry in ${LANGUAGE}_${COUNTRYCODE}${EXTRA_LANGUAGECHOOSER} \
-		             ${LANGUAGE}_${COUNTRYCODE}; do
-			# Is the locale we inherited really a complete locale?
-			LOCALE_LANGUAGECHOOSER_COMPLETE=$(echo $OLDLOCALE | grep "_" || true)
-			if grep -q "^${entry}$" $SUPPORTEDLOCALES; then
-				# Special handling of cases where the locale
-				# in languagechooser is NOT the combination of
-				# language_COUNTRY. Used for Norwegian
-				# Bokmal transition in order to keep no_NO as
-				# locale. May be used in the future for other
-				# special cases, so we'd better keep this.
-				if \
-				    [ "$LANGUAGE" = "${LANGUAGECODE_LANGUAGECHOOSER}" \
-				      -a \
-				      "$COUNTRYCODE" = "${COUNTRYCODE_LANGUAGECHOOSER}" \
-				      -a \
-				      "${LANGUAGE}_${COUNTRYCODE}" != "$OLDLOCALE" \
-				      -a \
-				      -n "${LOCALE_LANGUAGECHOOSER_COMPLETE}" \
-				    ] ;  then
-					# Explanation: we revert back to the
-					# locale inherited from the language
-					# step if the country step did NOT
-					# induce change in language and country
-					# but the resulting locale is different
-					# from the one we had in first step.
-					LOCALE=$OLDLOCALE
-				else
-					LOCALE="${entry}"
-				fi
-				break
+		# Is the locale we inherited really a complete locale?
+		LOCALE_LANGUAGECHOOSER_COMPLETE=$(echo $OLDLOCALE | grep "_" || true)
+		PREFERRED_LOCALE="$(preferred_locale "$LANGUAGE" "$COUNTRYCODE" "$ENCODING")"
+		if [ "$PREFERRED_LOCALE" ]; then
+			# Special handling of cases where the locale
+			# in languagechooser is NOT the combination of
+			# language_COUNTRY. Used for Norwegian
+			# Bokmal transition in order to keep no_NO as
+			# locale. May be used in the future for other
+			# special cases, so we'd better keep this.
+			if \
+			    [ "$LANGUAGE" = "${LANGUAGECODE_LANGUAGECHOOSER}" \
+			      -a \
+			      "$COUNTRYCODE" = "${COUNTRYCODE_LANGUAGECHOOSER}" \
+			      -a \
+			      "${LANGUAGE}_${COUNTRYCODE}" != "$OLDLOCALE" \
+			      -a \
+			      -n "${LOCALE_LANGUAGECHOOSER_COMPLETE}" \
+			    ] ;  then
+				# Explanation: we revert back to the
+				# locale inherited from the language
+				# step if the country step did NOT
+				# induce change in language and country
+				# but the resulting locale is different
+				# from the one we had in first step.
+				LOCALE="$OLDLOCALE"
+			else
+				LOCALE="$PREFERRED_LOCALE"
 			fi
-		done
+		fi
 	else
 		# LOCALE was valid
 		LOCALE=$OLDLOCALE
@@ -475,7 +498,7 @@
 	
 	# Fall back to a supported locale.
 	if [ -z "${LOCALE}" ]; then
-		if grep -q "^${FALLBACKLOCALE}$" $SUPPORTEDLOCALES; then
+		if grep -q "^${FALLBACKLOCALE} " $SUPPORTEDLOCALES; then
 			LOCALE="$FALLBACKLOCALE"
 		else
 			LOCALE=`echo $FALLBACKLOCALE | sed -e 's/[.@].*$//'`
@@ -506,20 +529,28 @@
 # We will select from supported locales
 # for LANGUAGE_COUNTRY
 if [ "$LOCALE" != "C" ] ; then
-	POSSIBLELOCALES=$(grep -e "^${LANGUAGE}_${COUNTRYCODE}" $SUPPORTEDLOCALES || true)
+	POSSIBLELOCALES=$(grep -e "^${LANGUAGE}_${COUNTRYCODE}" $SUPPORTEDLOCALES | cut -d' ' -f1 || true)
 	if [ -z "$POSSIBLELOCALES" ] ; then
-		POSSIBLELOCALES=$(grep -e "^${LANGUAGE}_${COUNTRYCODE_LANGUAGECHOOSER}" $SUPPORTEDLOCALES || true)
+		POSSIBLELOCALES=$(grep -e "^${LANGUAGE}_${COUNTRYCODE_LANGUAGECHOOSER}" $SUPPORTEDLOCALES | cut -d' ' -f1 || true)
 	fi
 	if [ $(echo $POSSIBLELOCALES | wc -w) -gt 1 ] ; then
 		CHOICES=""
+		DEFAULT=""
 		for i in $POSSIBLELOCALES ; do
 			if [ -z "$CHOICES" ] ; then
 				CHOICES=$i
 			else
 				CHOICES="$CHOICES, $i"
 			fi
+			if [ -z "$ENCODING" ] || [ "$(grep -e "^$(echo "$i" | sed 's/\./\\./g') " $SUPPORTEDLOCALES | cut -d' ' -f2)" = "$ENCODING" ]; then
+				DEFAULT="$i"
+			fi
 		done
 		db_subst $localecode LOCALELIST "$CHOICES"
+		db_fget $localecode seen
+		if [ "$RET" = true ]; then
+			db_set $localecode "$DEFAULT"
+		fi
 		db_input medium $localecode || [ $? -eq 30 ]
 		if ! db_go; then
 			exit 10
@@ -531,7 +562,7 @@
 	# Ask for additional locales to be generated
 	CHOICES=
 	# *.UTF-8@euro locales are deprecated; don't use them.
-	for i in $(grep -v '\.UTF-8@euro$' $SUPPORTEDLOCALES | grep -v "^$LOCALE$"); do
+	for i in $(grep -v '\.UTF-8@euro$' $SUPPORTEDLOCALES | cut -d' ' -f1 | grep -v "^$LOCALE$"); do
 		if [ -z "$CHOICES" ]; then
 			CHOICES="$i"
 		else
Index: README
===================================================================
--- README	(revision 46988)
+++ README	(working copy)
@@ -268,7 +268,7 @@
 		     If we're lucky, everything is OK and 3-letter codes
                      will work..:-)
 
-   -countrycode     =default value for country choice in countrychoose
+   -countrycode     =default value for country choice in countrychooser
                      MUST be a valid ISO-3166 alpha-2 code
 
                      DO NOT GUESS IT. Please check in the iso-codes
@@ -293,6 +293,11 @@
                               these is no en_US@euro locale. However, if
                               Ireland is chosen, the locale will be en_IE@euro
 
+   -encoding        =preferred encoding for this language
+
+		     If possible, a locale with this encoding will be
+		     selected as the default.
+
    -langlist        =colon-separated list of possible fallback languages
 		     It will usually be empty except for languages
 		     where fallback to something else than English is wished
Index: get-SUPPORTED
===================================================================
--- get-SUPPORTED	(revision 46988)
+++ get-SUPPORTED	(working copy)
@@ -1,7 +0,0 @@
-#!/bin/sh
-#
-# Get the SUPPORTED list of locales
-set -e
-[ -r /usr/share/i18n/SUPPORTED ] || exit 1
-rm -rf debian/SUPPORTED-short >/dev/null 2>&1
-cat /usr/share/i18n/SUPPORTED| cut -f1 -d ' ' | uniq >debian/SUPPORTED-short
Index: Makefile
===================================================================
--- Makefile	(revision 46988)
+++ Makefile	(working copy)
@@ -1,4 +1,4 @@
-all: debian/SUPPORTED-short debian/short-tmp/shortlists debian/templates check-scripts check-data check-utf8
+all: debian/short-tmp/shortlists debian/templates check-scripts check-data check-utf8
 
 LIST     = languagelist
 L10NLIST = languagelist.l10n
@@ -16,9 +16,6 @@
 debian/templates: debian/templates.base debian/short-tmp/shortlists
 	./mk_shortlist_templates
 
-debian/SUPPORTED-short:
-	./get-SUPPORTED
-
 debian/short-tmp/shortlists: debian/iso-codes
 	./mkshort
 
@@ -48,5 +45,5 @@
 	DEBIAN_FRONTEND=dialog DEBCONF_DEBUG=developer /usr/share/debconf/frontend ./localechooser
 
 clean:
-	$(RM) localechooser.templates debian/templates debian/templates.lang debian/templates.tmp debian/templates.base SUPPORTED-short debian/iso-3166.tab
+	$(RM) localechooser.templates debian/templates debian/templates.lang debian/templates.tmp debian/templates.base debian/iso-3166.tab
 	$(RM) -rf debian/short-tmp debian/iso-codes
