This page last changed on Nov 16, 2005 by rossmason.

Mule supports internationalisation of exception messages, or any other type of string message.

Mule has Support for the following Languages-

  • English
  • Japanese

Using Internationalisation

Mule uses the java ResourceBundle class to load messages from properties files on the classpath based on the current systems locale. Mule only has English messages but may have translations in future.

Users will need to understand about how MUle loads messages if they want to throw any MUle exception that extends UMOException. This is the base class of all Mule checked exceptions and can only be constructed using internationalised messages.

Mule internationalised messages are represented by the org.mule.config.i18n.Message . This object can be constructed with a message id and zero or more message parameters. Mule has a list of core messages that can be found in META-INF/service/org.mule/i18n/core-message.properties. Constants for these messages can be found in the org.mule.config.i18n.Messages class.

To create a message for an exception you would do the following -

UMOException e = new MuleException(
    new Message(Messages.SOMETHING_FAILED));

throw e;

The argument in the Message constructor refers to a error code constant.

You can also pass in message parameters when creating a Message object. these will be used to embed variable information in the message. The message constants defined in org.mule.config.i18n.Messages uses X's to denote how many parameters the message expects. For example

UMOException e = new InitialisationException(
       new Message(Messages.FAILED_TO_INITIALISE_X, 
                              "whatever this is"));

throw e;

Using custom message bundles

When writing Mule extensions or even applications that want to use the Mule internationalisation class, developers can supply custom message bundles containing message specific to their application or extension. To do this developers should create a bundle in the form of -

1=Error message one
2=Error message with 2 parameters; param {0} and param {1}
...

where the number is the message id and the actual message comes after. Note that message parameters are specified using '{0}' notation which is standard when using the java MessageFormat class.

The file should be named xxx-message.properties where xxx is the identifying name for this bundle. This file should then be located in your jar under META-INF/services/org/mule/i18n/xxx-messages.properties.

To load a message from this bundle the developer just needs to pass in the resource bundle name -

Message m = new Message("xxx", 2, "one", "two");
System.out.pritln(m.toString());

This loads the message with id 2 from xxx-message.properties, formats the message with 2 parameters "one" and "two" and prints out the message to System.out -

Error message with 2 parameters; param one and param two
Document generated by Confluence on Nov 27, 2006 10:27