Community contributed extensions

@messages

Module messages provides a web based tool for managing your application’s localizations. You need to enable the messages module in the conf/application.conf file

module.messages=${play.path}/modules/messages-{version}

or this line to the dependencies.yml file

- play -> messages {version}

And next you will need to add the following line to the conf/routes file

*     /    module:messages

Then you can access the tool at http://localhost:9000/@messages.

New in version 1.1

- Support for default language editing
- Add regexp for i18n javascript function in order to provide support for messages in javascript files
- Write selected tab information in a cookie so that selected tab does not change after refresh (Needs jquery.cookie.js)
- Fix language drop down event binding to “change” instead of "click"
- Fix language not selected after refresh bug

Message keys lookup

The tool will use simple regexp to look for localization keys in the application sources. The default path used is app, but this can be configured with the property messages.srcDir. The lookup uses regexp to scan the source files and finds the following patterns:
bc. // localization in java
Messages.get(“keyname”);
// localization with arguments
Messages.get(“keyname”, paramA, paramB);
// validation error message
Validation.addError(“fieldName”, “keyname”, param1, param2);
{ localization in template }
&{‘keyname’, param1, param2}
{ template localization inside a tag }
{ name = messages.get(“keyname”); name2 = messages.get(‘keyname2’); }
{ javascript localization with i18n }
#{i18n /}

The lookup will work in most cases, but it cannot of course find the right value for generated localization keys. For example consider the following code

UserType type = UserType.ADMIN;
String localizedString = Messages.get("user.type." + userType.name().toLowerCase());

In this case the tool will find the first part of the key user.type. when the valid key would be user.type.admin. To help you with this special, but common case @messages has support for ignore and **keep* lists.

Ignore list

Ignore list is intended for those keys that the tool finds from the sources that are invalid for some reason, like the user.type. in our example. To add the key to the ignore list you need to check the ignore checkbox when the key shows up in the new keys. Ignored keys can be found under the ignored keys link in the new keys tab.

Keep list

Keep list is intended for those keys that the tool cannot find from the sources, like the user.type.admin in our example. To add the key to the keep list you need to check the keep checkbox if the key shows up in the obsolete keys tab. New keys added with the tool will have the keep checkbox checked by default.

A key in the keep list can be found in the new keys or existing keys tab, depending on whether it has been localized for the selected language or not.

Configuration reference

messages.srcDir, default app: A comma separated list of paths the tool uses when it looks for localization keys in the sources.
messages.targetDir, default conf: Path to the directory where the tool will read and write the messages files.
messages.resource, default DefaultMessageResource: Class which is used to load and save the localizations.