File: mkshort

package info (click to toggle)
localechooser 2.84
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 1,612 kB
  • sloc: sh: 1,096; perl: 187; makefile: 71; awk: 42
file content (80 lines) | stat: -rwxr-xr-x 2,128 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#! /bin/sh

set -e

ISO3166TAB=debian/iso_3166.tab
SUPPORTED=/usr/share/i18n/SUPPORTED
TAB="	"

rm -rf debian/short-tmp
rm -rf debian/locales
mkdir debian/short-tmp
mkdir debian/locales

echo "Building short lists of countries..."
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
	# Only if iso-codes have some translations
	if [ -f debian/iso-codes/$lang_variant.po ]; then
		msgconv debian/iso-codes/$lang_variant.po -t UTF-8 --stringtable-output | \
			tail -n +3 | \
			sed -e 's/" = "/\t/' -e 's/^"//' -e 's/";$//' | \
			awk '/^.+$/{print}' >$tabfile
	fi

	outfile=debian/short-tmp/$lang_variant.short
	lastlocale=C
	: >$outfile
	for locale in $( (grep -e "^${lang}_" $SUPPORTED 2>/dev/null || true) | \
			sed -e 's/[@. ].*//' | sort | uniq); do
		if [ "$locale" = en_DK ] ; then
			# Don't add Denmark to shortlist for English (per #276067)
			continue
		fi

		code=$(echo "$locale" | sed -e 's/.*_//')
		line=$(grep -e "^$code" $ISO3166TAB || true)
		lastlocale=$locale
		if [ "$line" ]; then
			OLD_IFS="$IFS"
			IFS='	'
			set $line
			IFS="$OLD_IFS"
			if [ "$2" ]; then
				if [ "$lang" != en ] ; then
					translation=$( (grep "^$2$TAB" $tabfile 2>/dev/null || true) | sed -e 's/^.*\t//')
					if [ "$translation" ]; then
						printf '%s\t%s\t%s\n' "$1" "$translation" "$2" >>$outfile
					else
						printf '%s\t%s\t%s\n' "$1" "$2" "$2" >>$outfile
					fi
				else
					printf '%s\t%s\t%s\n' "$1" "$2" "$2" >>$outfile
				fi
			fi
		fi
	done

	if [ $(wc -l <$outfile) -le 1 ]; then
		rm -f $outfile
	else
		echo $lang_variant
		localedef -c -f UTF-8 -i $lastlocale debian/locales/$lastlocale.UTF-8
		LOCPATH=`pwd` LC_ALL=debian/locales/$lastlocale.UTF-8 \
			sort -k 2.1 $outfile >$outfile.tmp && \
			mv $outfile.tmp $outfile
	fi
done

# Create a file listing the countries that have shortlists
SHORTLISTS=debian/short-tmp/shortlists
: >$SHORTLISTS

for file in debian/short-tmp/*.short; do
	lang=$(basename $file .short)
	echo "$lang" >>$SHORTLISTS
done