File: mk_shortlist_templates

package info (click to toggle)
localechooser 1.37
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 708 kB
  • ctags: 24
  • sloc: sh: 740; perl: 201; makefile: 82; awk: 42; python: 38
file content (112 lines) | stat: -rwxr-xr-x 3,653 bytes parent folder | download
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
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/bin/sh

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="countrychooser/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

    # Get the default value.
    if [ "$LANG" != en ]; then
    	field="Default-$LANG.UTF-8"
    else
	field="Default"
    fi
    LANG_DEFAULT_COUNTRY=$(awk -v ITEM="$field:" -f template_get_item.awk \
	$TEMPLATE_TMP | head -1 | sed "s/-$LANG.UTF-8//")
	
    echo "$LANG"

    # Write the 'template header' to the file
    echo "Template: $TEMPLATE_NAME-$LANG" >>$TEMPLATE_NEW
    echo "Type: select" >>$TEMPLATE_NEW
    if [ -n "$LANG_DEFAULT_COUNTRY" ] ; then
	echo "$LANG_DEFAULT_COUNTRY" >>$TEMPLATE_NEW
    fi
    
    # 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