Last active
August 29, 2015 14:02
-
-
Save maripo/3c2e03df7182ea5829cd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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