Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sort Android strings.xml in Alphabetical Order

While programming my Android app I just kept inserting elements in strings.xml with no order whatsoever. Is there a shortcut key (like Ctrl+Shift+F can organize android: attributes in an XML layout file) that sorts string elements alphabetically?

like image 772
Akash Avatar asked Aug 09 '12 20:08

Akash


3 Answers

For those who have access to GNU or similar *nix command-line utils, you can do the following:

cat <(head -n 1 strings.xml) <(head strings.xml -n -2 | tail -n +2 | sort ) <(tail -n 2 strings.xml)

You may need to tweak the numbers slightly if your strings.xml has a larger XML header.

like image 186
Steve Pomeroy Avatar answered Oct 26 '22 23:10

Steve Pomeroy


For anyone else who bumps into this. Copy all the string elements, paste into an Excel spreadsheet sort A-Z and then copy and paste back.

like image 41
RobCroll Avatar answered Oct 27 '22 00:10

RobCroll


This is actually a feature in ADT plugin:

enter image description here

However, it only sort elements in Resources viewer, it doe not modify anything in the original strings.xml file.

like image 39
yorkw Avatar answered Oct 26 '22 22:10

yorkw