aboutsummaryrefslogtreecommitdiffstats
path: root/main/project
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2011-10-08 09:25:44 +0200
committerSamuel Tardieu <sam@rfc1149.net>2011-10-08 09:32:35 +0200
commit74d6ff56dbbf4b868a24a6b31ec296b48bc60273 (patch)
tree373bfeb4ca09d9718e255e09d8621fb35c39aea8 /main/project
parent1455819e59d5e2fb55c5fcbc562b1cfdbe47a80d (diff)
downloadcgeo-74d6ff56dbbf4b868a24a6b31ec296b48bc60273.zip
cgeo-74d6ff56dbbf4b868a24a6b31ec296b48bc60273.tar.gz
cgeo-74d6ff56dbbf4b868a24a6b31ec296b48bc60273.tar.bz2
Add an extra script to find and remove unused translation strings
Diffstat (limited to 'main/project')
-rwxr-xr-xmain/project/localization/findextratranslations.sh54
-rwxr-xr-xmain/project/localization/findmissingtranslations.sh8
-rw-r--r--main/project/localization/funcs.sh5
3 files changed, 62 insertions, 5 deletions
diff --git a/main/project/localization/findextratranslations.sh b/main/project/localization/findextratranslations.sh
new file mode 100755
index 0000000..56aedd3
--- /dev/null
+++ b/main/project/localization/findextratranslations.sh
@@ -0,0 +1,54 @@
+#!/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() {
+ (cd $sourcedir && grep -m 1 R.string.$1 $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
diff --git a/main/project/localization/findmissingtranslations.sh b/main/project/localization/findmissingtranslations.sh
index 846e0b3..4c47cbd 100755
--- a/main/project/localization/findmissingtranslations.sh
+++ b/main/project/localization/findmissingtranslations.sh
@@ -1,8 +1,8 @@
#!/bin/sh
-getnames () {
- sed -ne 's/^.*<string\s*name\s*=\s*"\([^\"]*\)".*$/\1/p' $1
-}
+cd `dirname "$0"`
+
+. ./funcs.sh
finddiffs () {
echo "translations missing or not in the right place for language '$1':" > $1.missing
@@ -25,8 +25,6 @@ usage() {
exit 1
}
-cd `dirname "$0"`
-
alllangs=`find ../../res/values-* -name "strings.xml" | sed "s/^.*values-\(..\).*$/ \1/"`
if [ $# -ne 1 ]; then
diff --git a/main/project/localization/funcs.sh b/main/project/localization/funcs.sh
new file mode 100644
index 0000000..f54dccd
--- /dev/null
+++ b/main/project/localization/funcs.sh
@@ -0,0 +1,5 @@
+# Utility functions for location-aware programs
+
+getnames () {
+ sed -ne 's/^.*<string\s*name\s*=\s*"\([^\"]*\)".*$/\1/p' $1
+}