Child pages
  • Utilities
Skip to end of metadata
Go to start of metadata

Overview is a simple perl script that can be helpful in managing files.  It provides two basic features:

  • Searches for unused message codes within a project/module/etc.
  • Compares files from different locales for missing message codes

The script can be found here:

Disclaimer: This script has only been used on a single module to date and is not foolproof.  The script writes all its changes to a separate output file, and I recommend reviewing the outputs before replacing any existing .properties files. Also, make sure to read the limitations of the script as documented below.


Finding unused message codes

To find unused message codes, run messageUtils with the following parameters: -s [MESSAGE_FILE] [TARGET_DIRECTORY] [OUTPUT_FILE]

The script will load in all the message codes in the message file and search for references to each code in all files in the target directory (and subdirectories, excluding existing .properties files).  The output file will contain all the message codes in the message file, except that all codes that weren't found in the target directory will be moved to the end of the file, after a comment line "NOT FOUND".  The user can then manually triage this list and remove the unused codes.

NOTE: This script only searches for static references to message codes.  If a code is only referenced dynamically (i.e., Context.getMessageSourceService().getMessage("somePrefix." + someVariable)), it will be erroneously added to the "Not found" list.    

NOTE: This script could take a long time to execute, as it's not particularly efficient. Currently, it searches through each file for each code individually... I assume that the speed would be improved if it only cycled through the files once.  

Comparing files for different locales

To compare the message codes in two files from different locales, run messageUtils with the following parameters: -c [MESSAGE_FILE] [TARGET_FILE] [OUTPUT_FILE]

The script will load all the message codes in the message file (usually and then compare them with the codes in the target file (usually a localized file, i.e.  The output file will be  revamped version of the target file.  Any codes found in the target file, but not found in the the message file, will be removed from the output file; any messages in the message file that are not found in the target file will be added to the end of the output file, after a comment line "NOT FOUND".  These codes can then be translated into the appropriate language.

NOTE: The script will ignore any codes listed after the "NOT FOUND" line in the target file. Therefore, after all the codes have been translated, this line should be removed, or these translations will be lost on subsequent executions of the script.

As an example, given the existing files:

Running " -c" will result in the creation of the following output file:
<!--NOT FOUND-->

Someone could then translate the messages after "NOT FOUND" into the appropriate language, and then remove the "NOT FOUND" line.


Feel free to send any feedback to, but also please cc the developer's list.



A Groovy message utility for comparing message codes to codes used within source code.

  • Scans a specified message bundle (defaults to main bundle) and source code, listing out both unused message codes (in bundle, not in code) and missing message codes (in code, but not in message bundle).

The script can be found here:


usage: Usage: messageUtils.groovy [options] /path/to/folder/with/messages/
 -h,--help              Show this help information
 -l,--locale <locale>   Specify locale for messages to be scanned
 -m,--missing-only      Only list missing message codes (used in source,
                        but not defined)
 -s,--summary           Show summary stats
 -u,--unused-only       Only list unused message codes (defined, but never
                        used in source)


E-mail to the OpenMRS Developers list.