Skip to content

Instantly share code, notes, and snippets.

@maripo
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maripo/3c2e03df7182ea5829cd to your computer and use it in GitHub Desktop.
Save maripo/3c2e03df7182ea5829cd to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# replace_resource_ids.pl
# It replaces resource IDs (R.string.xxx) in source files with resource string
# and write in STDOUT.
# usage: ./replace_resource_ids.pl strings.xml Hoge.java
use strict;
my $dictFile = $ARGV[0];
my $convertFile = $ARGV[1];
my %dict = ();
{
open my $d, $dictFile or die "Error";
while(<$d>) {
if ($_ =~ /^\s*<string name\=\"(.*?)\">(.*)<\/string>\s*$/) {
my $key = $1;
my $str = $2;
$key =~ s/\./_/g;
# TODO
$str =~ s/[\)\(\/]//g;
$dict{$key} = $str;
}
}
close $dictFile;
}
my @keys = keys %dict;
open my $c, $convertFile or die "Error";
while (<$c>) {
my $line = $_;
for my $key (@keys) {
my $str = $dict{$key};
$line =~ s/R\.string\.$key/\"$str\"/g;
}
print $line;
}
close $convertFile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment