16.3. Labels

JSF supports the internationalization of user interface labels and descriptive text with the <f:loadBundle />. In Seam applications, you can either take this approach, or use the Seam messages component to display templated labels with embedded EL expressions.

16.3.1. Defining labels

Make your internationalized labels available with Seam's java.util.ResourceBundle, available to the application as a org.jboss.seam.core.resourceBundle. By default, Seam uses a resource bundle named messages, so you will need to define your labels in files named messages.properties, messages_en.properties, messages_en_AU.properties, etc. These files usually belong in the WEB-INF/classes directory.
So, in messages_en.properties:
Hello=Hello
And in messages_en_AU.properties:
Hello=G'day
You can select a different name for the resource bundle by setting the Seam configuration property named org.jboss.seam.core.resourceLoader.bundleNames. You can even specify a list of resource bundle names to be searched (depth first) for messages.
<core:resource-loader> 
  <core:bundle-names> 
    <value>mycompany_messages</value> 
    <value>standard_messages</value>       
  </core:bundle-names> 
</core:resource-loader>
To define a message for one particular page, specify it in a resource bundle with the same name as the JSF view ID, with the leading / and trailing file extension removed. So, we could put our message in welcome/hello_en.properties if we only needed to display the message on /welcome/hello.xhtml.
You can even specify an explicit bundle name in pages.xml:
<page view-id="/welcome/hello.xhtml" bundle="HelloMessages"/>
Then we could use messages defined in HelloMessages.properties on /welcome/hello.xhtml.

16.3.2. Displaying labels

If you define your labels with the Seam resource bundle, you can use them without having to type <f:loadBundle... /> on each page. Instead, you can type:
<h:outputText value="#{messages['Hello']}"/>
or:
<h:outputText value="#{messages.Hello}"/>
Even better, the messages themselves may contain EL expressions:
Hello=Hello, #{user.firstName} #{user.lastName}
Hello=G'day, #{user.firstName}
You can even use the messages in your code:
@In private Map<String, String> messages;
@In("#{messages['Hello']}") private String helloMessage;

16.3.3. Faces messages

The facesMessages component is a convenient way to display success or failure messages to the user. The functionality we just described also works for Faces messages:
@Name("hello") 
@Stateless 
public class HelloBean implements Hello { 
  @In FacesMessages facesMessages; 
  public String sayIt() { 
    facesMessages.addFromResourceBundle("Hello"); 
  } 
}
This will display Hello, Gavin King or G'day, Gavin, depending upon the user's locale.