Message.properties Utilities

messageUtils.pl

Overview

messageUtils.pl is a simple perl script that can be helpful in managing messages.properties files.  It provides two basic features:

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

The script can be found here: http://svn.openmrs.org/openmrs-contrib/utilities/messageUtils/

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.

Usage

Finding unused message codes

To find unused message codes, run messageUtils with the following parameters:

messageUtils.pl -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 message.properties files for different locales

To compare the message codes in two files from different locales, run messageUtils with the following parameters:

messagesUtils.pl -c [MESSAGE_FILE] [TARGET_FILE] [OUTPUT_FILE]

The script will load all the message codes in the message file (usually message.properties) and then compare them with the codes in the target file (usually a localized file, i.e. messages_es.properties).  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:

messages.properties:

general.man=Man
general.woman=Woman
general.hot=Hot
general.cold=Cold

messages_es.properties:

general.hot=Caliente
general.man=Senior

Running "messageUtils.pl -c messages.properties messages_es.properties messages_es_output.properties" will result in the creation of the following output file:

general.man=Senior
general.hot=Caliente
<!--NOT FOUND-->
general.woman=Woman
general.cold=Cold

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

Feedback

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

messageUtils.groovy

Overview

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

  • Scans a specified message bundle (defaults to main message.properties 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: http://svn.openmrs.org/openmrs-contrib/utilities/messageUtils/

Usage

usage: Usage: messageUtils.groovy [options] /path/to/folder/with/messages/
              /path/to/openmrs/source/
 -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)

Feedback

E-mail to the OpenMRS Developers list.