This Tech Tip shows you how to clean up property files.
It demonstrates the use of the UNIX command line as well as
the Bundlizer tool to identify duplicate or unused entries.

Removing “stale” Bundle.properties entries is important:
Not only do they create unnecessary work for localizers
who translate these files,
but unused keys also incur more runtime overhead.
It is easy to accidentally end up with unused key entries
while your code develops, so you ought
to check your property files even if you don't suspect
any “stale” entries.

Using the Unix Command Line to Scan Bundle Files

In Unix, you can use the command line to scan your files
for unused Bundle.properties entries.
This is an example Unix shell command by Tor Norbye using nawk.

It looks for duplicates: When the same key is used more than once,
you are alerted to this since you will need
to decide which value to keep.

It cleans up formatting in the file:
For instance, it removes empty lines.

When you are done, it saves the resulting file.

Be aware that you should definitely check the results
before accepting any proposed changes.
Determining if a key is unused or not is not a task which can be
done fully automatically.
If for instance your code is computing keys
rather than looking them up directly,
Bundlizer will not be able to identify them
and will erroneously report these keys unused.

Patching Bundlizer

If you have downloaded the Bundlizer's source code,
you can adapt this utility to your own needs.
For example, the
executable jar
file mentioned above includes two improvements by Tor Norbye.
The first patch makes Bundlizer also look in XML files for key references;
the second makes the tool more robust against the encounter of
non-commented lines that do not contain any “=” signs.