summaryrefslogtreecommitdiffstats
path: root/tools/findunused
diff options
context:
space:
mode:
authorAndroid (Google) Code Review <android-gerrit@google.com>2009-07-24 16:09:15 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2009-07-24 16:09:15 -0700
commitf7eee71bed9dc3990533b246430b9d5b49357bdd (patch)
treebf5649486a957663dc5356739cbab6761956d64c /tools/findunused
parent22979479fb7bfa26f709043d1648eaa36bfa1e4a (diff)
parent84c9d60322e4605d2d96eb8b058e21125f2ad7fe (diff)
downloadandroid_development-f7eee71bed9dc3990533b246430b9d5b49357bdd.tar.gz
android_development-f7eee71bed9dc3990533b246430b9d5b49357bdd.tar.bz2
android_development-f7eee71bed9dc3990533b246430b9d5b49357bdd.zip
am 84c9d603: Merge change 5271 into donut
Merge commit '84c9d60322e4605d2d96eb8b058e21125f2ad7fe' * commit '84c9d60322e4605d2d96eb8b058e21125f2ad7fe': Script to strip out unused translations when you change the base strings.xml.
Diffstat (limited to 'tools/findunused')
-rwxr-xr-xtools/findunused/findunusedtranslations103
1 files changed, 103 insertions, 0 deletions
diff --git a/tools/findunused/findunusedtranslations b/tools/findunused/findunusedtranslations
new file mode 100755
index 000000000..878681e38
--- /dev/null
+++ b/tools/findunused/findunusedtranslations
@@ -0,0 +1,103 @@
+#!/usr/bin/perl
+
+sub usage {
+ print STDERR "Usage: findunusedtranslations values/strings.xml\n";
+ print STDERR "\n";
+ print STDERR "Will read values/strings.xml and rewrite\n";
+ print STDERR "values-xx/strings.xml and values-xx-rYY/strings.xml\n";
+ print STDERR "files to remove strings that no longer appear in the\n";
+ print STDERR "base strings file.\n";
+
+ exit 1;
+}
+
+if ($#ARGV != 0) {
+ usage();
+}
+
+unless ($ARGV[0] =~ /^(.*)\/values([^\/]*)\/(.*\.xml)/) {
+ print STDERR "Bad format for $ARGV[0]\n";
+ usage();
+}
+
+unless (-f $ARGV[0]) {
+ print STDERR "$0: $ARGV[0]: No such file\n";
+}
+
+$prefix = $1;
+$values = $2;
+$suffix = $3;
+
+if ($values =~ /^(-mcc[^-]*)*(-mnc[^-]*)*(.*)$/) {
+ $pattern1 = "$prefix/values$1$2-??$3/$suffix";
+ $pattern2 = "$prefix/values$1$2-??-r??$3/$suffix";
+} else {
+ $pattern1 = "$prefix/values-??$values/$suffix";
+ $pattern2 = "$prefix/values-??-r??$values/$suffix";
+}
+
+@matches = (glob($pattern1), glob($pattern2));
+
+open(IN, "<$ARGV[0]");
+while (<IN>) {
+ if (/<string [^>]*name="([^"]*)"/) {
+ $string{$1} = 1;
+ }
+ if (/<string-array [^>]*name="([^"]*)"/) {
+ $stringarray{$1} = 1;
+ }
+ if (/<plurals [^>]*name="([^"]*)"/) {
+ $plurals{$1} = 1;
+ }
+}
+close(IN);
+
+for $match (@matches) {
+ print "Rewriting $match\n";
+ $suppress = 0;
+ $text = "";
+ $changes = 0;
+
+ open(IN, "<$match");
+ while (<IN>) {
+ if (/<string [^>]*name="([^"]*)"/) {
+ if ($string{$1} == 0) {
+ $suppress = 1;
+ $changes = 1;
+ }
+ }
+ if (/<string-array [^>]*name="([^"]*)"/) {
+ if ($stringarray{$1} == 0) {
+ $suppress = 1;
+ $changes = 1;
+ }
+ }
+ if (/<plurals [^>]*name="([^"]*)"/) {
+ if ($plurals{$1} == 0) {
+ $suppress = 1;
+ $changes = 1;
+ }
+ }
+
+ $text .= $_ unless ($suppress);
+
+ if (/<\/string/) {
+ $suppress = 0;
+ }
+ if (/<\/string-array/) {
+ $suppress = 0;
+ }
+ if (/<\/plurals/) {
+ $suppress = 0;
+ }
+ }
+ close(IN);
+
+ if ($changes) {
+ open(OUT, ">$match");
+ print OUT $text;
+ close(OUT);
+ } else {
+ print "(no changes)\n";
+ }
+}