Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: is there an easy way to find all the Strings in my project?

I want to scan my Android project for all hardcoded Strings so I can localize the project, putting the Strings in strings.xml. I see an option in Eclipse to 'Externalize Strings...' but it isn't specific to Android.

I know you can refactor individual strings but I'd like to refactor all the Strings at once. I've got a ton of files, and I'm trying to avoid going through each one manually.

like image 692
Christopher Perry Avatar asked Nov 06 '11 03:11

Christopher Perry


1 Answers

I would just open up a terminal window(putty if you are on windows) at the root directory of your project. You can then run something like the following:

grep -r --include=*.java '="[^"\r\n]*"' ./*  --to look for something like this String test="text";, a string with =""
or
grep -r --include=*.java '"[^"\r\n]*"' ./*  -- to look for any string, anything enclosed in ""

Of course the next part is to actually substitute the Strings into the Strings.xml, that could be scripted out as well, but may take more tinkering.

like image 135
broschb Avatar answered Sep 25 '22 14:09

broschb