Monday, July 04, 2011

Externalizing Android strings in Eclipse

The Android SDK documents highly recommend the practice of externalizing all of your strings to an external XML file (strings.xml), instead of hard coding them in java or other XML documents.

Why? So its easier for you to provide translations for your app down the road if you want.

For a long time I have put off doing this in any of my Android applications, as its a hugely time consuming task with seemingly little benefit to me.. until recently when I discovered a handy feature of the Android ADT plugin for Eclipse: Refactoring Android Strings!

Highlite any string, click on Refactor in the main Eclipse menu, Android, Extract Anroid String.

It will automatically extract your string into the strings.xml file, and it will generate the necessary API call in place to load your string!  Handy!



No comments: