aboutsummaryrefslogtreecommitdiffstats
path: root/main/project/localization/findextratranslations.sh
blob: 0a2d5768d534a2961059b16f40bb49856a01b293 (plain)
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
#!/bin/sh

cd `dirname "$0"`

. ./funcs.sh

sourcedir=../../src/cgeo/geocaching
sourcefiles=`cd $sourcedir && find . -name '*.java'`
xmlfiles=`echo ../../res/*/*.xml ../../AndroidManifest.xml`
first=true
if [ x$1 = x-f ]; then
    remove=true
elif [ x$1 = x-n ]; then
    remove=false
else
    echo "Usage: findextratranslations.sh [ -n | -f]" >&2
    echo "         -n: only display" >&2
    echo "         -f: force unused strings removal" >&2
    exit 1
fi

checkpresent() {
    # Status messages are dynamically referenced by name, so they will
    # not appear in the source.
    if [ -z `echo $1 | sed -e 's/^status_.*$//'` ]; then
        return 0
    fi
    (cd $sourcedir && grep -m 1 -E "\WR\.(string|plurals)\.$1\W" $sourcefiles > /dev/null) || \
      grep -m 1 @string/$1 $xmlfiles > /dev/null
}

checkname() {
    if ! checkpresent $1; then
        checkfirst
        echo "   - $1"
	if $remove; then
	    remove_from_strings $1
	fi
    fi
}

remove_from_strings() {
   sed -i -e "/<string name=\"$1\">/d" ../../res/values*/strings.xml
}

checkfirst() {
    if $first; then
        echo Possibly unreferenced names:
	first=false
    fi
}

for name in `getnames ../../res/values/strings.xml`; do
    checkname $name
done

if $first; then
    echo All names seem to be in use
fi