File: mktemplates.shortlist

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 (99 lines) | stat: -rwxr-xr-x 3,044 bytes parent folder | download | duplicates (6)
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/sh

export LC_ALL=C # avoid sed hang

SHORTLIST_DIR="./debian/short-tmp"
SHORTLIST_LANGS=$(cd $SHORTLIST_DIR; ls *.short | cut -d. -f1)

TEMPLATE_BASE="./debian/templates.base"
TEMPLATE_TMP="./debian/templates.tmp"
TEMPLATE_NEW="./debian/templates"
TEMPLATE_NAME="localechooser/shortlist"

NL="
"

print_trans () {
	ITEM_TRANS=$(awk -v ITEM="$1-$LANG.UTF-8:" \
		-f template_get_item.awk $TEMPLATE_TMP)
	if [ -n "$ITEM_TRANS" ] ; then
		echo "$ITEM_TRANS"
	else
		# We use the original entry as default
		REGEXP="s/$1:/$1-$LANG.UTF-8:/"
		echo "$2" | sed "$REGEXP"
	fi
}

# First create empty new files
:>$TEMPLATE_NEW
:>$TEMPLATE_TMP

# Extract the template for the shortlists to TEMPLATE_TMP
# Extract all other templates to TEMPLATE_NEW
awk -v TFILE1="$TEMPLATE_TMP" -v TFILE2="$TEMPLATE_NEW" \
	-v TEMPLATE="$TEMPLATE_NAME" -f template_extract.awk \
	$TEMPLATE_BASE
echo "" >>$TEMPLATE_NEW

# Get the English versions of the template items
EN_CHOICES=$(awk -v ITEM="Choices:" -f template_get_item.awk $TEMPLATE_TMP)
EN_DESCR=$(awk -v ITEM="Description:" -f template_get_item.awk $TEMPLATE_TMP)

# Add new templates for each language that needs a shortlist
for LANG in $SHORTLIST_LANGS; do
	echo "$LANG"

	# Write the 'template header' to the file
	echo "Template: $TEMPLATE_NAME/$LANG" >>$TEMPLATE_NEW
	echo "Type: select" >>$TEMPLATE_NEW

	# Next we put the countrycodes in the untranslated shortlist
	SHORTLIST=
	for COUNTRYCODE in $(cat $SHORTLIST_DIR/$LANG.short | cut -f 1) ; do
		SHORTLIST="$SHORTLIST$COUNTRYCODE, "
	done
	C_CHOICES=$(echo $EN_CHOICES | sed "s/Choices:/Choices-C:/")
	REGEXP="s/\${SHORTLIST}, /$SHORTLIST/"
	echo "$C_CHOICES" | sed "$REGEXP" >>$TEMPLATE_NEW

	# Next we build a shortlist containing the countrynames in English
	SHORTLIST=
	OLD_IFS="$IFS"
	IFS="$NL"
	COUNTRYLIST=
	for COUNTRYNAME in $(cut -f 3 $SHORTLIST_DIR/$LANG.short); do
		# Comma's in countrynames must be double-escaped here
		# in order to end up escaped in the final list.
		SL_NAME=$(echo "$COUNTRYNAME" | sed -e 's/,/\\\\,/')
		SHORTLIST="$SHORTLIST$SL_NAME, "
	done
	IFS="$OLD_IFS"
	REGEXP="s/\${SHORTLIST}, /$SHORTLIST/" >>$TEMPLATE_NEW
	echo "$EN_CHOICES" | sed "$REGEXP" >>$TEMPLATE_NEW

	# Next we build the translated shortlist containing translated countrynames
	if [ "$LANG" != en ]; then
		SHORTLIST=
		OLD_IFS="$IFS"
		IFS="$NL"
		COUNTRYLIST=
		for COUNTRYNAME in $(cut -f 2 $SHORTLIST_DIR/$LANG.short) ; do
			# Comma's in countrynames must be double-escaped here
			# in order to end up escaped in the final list.
			SL_NAME=$(echo "$COUNTRYNAME" | sed -e 's/,/\\\\,/')
			SHORTLIST="$SHORTLIST$SL_NAME, "
		done
		IFS="$OLD_IFS"
		TRANS_CHOICES=$(print_trans "Choices" "$EN_CHOICES")
		REGEXP="s/\${SHORTLIST}, /$SHORTLIST/" >>$TEMPLATE_NEW
		echo "$TRANS_CHOICES" | sed "$REGEXP"  >>$TEMPLATE_NEW
	fi

	# Finally we add the description and translated description
	echo "$EN_DESCR" >>$TEMPLATE_NEW
	if [ ! "$LANG" = en ]; then
		print_trans "Description" "$EN_DESCR" >>$TEMPLATE_NEW
	fi
	echo "" >>$TEMPLATE_NEW
done