Language localisation in JSF and Seam
This article introduces the mechanisms for internationalising a web application built using JavaServer Faces (JSF) application and the Seam Framework for language localisation (L10N), expanding on the brief introduction in the Seam manual, Chapter 16. Internationalization .
Simple labels
In the most simple case, as described in the Seam manual, you define a user-interface text labels in a properties file for each localisation.
# messages.properties - English localisation order = Order
# messages_fr.properties - French localisation order = Commande
Then display the label in a Facelets view using an Expression Language (EL) expression that uses the messages Seam component.
<h1>#{messages.order}</h1>
This syntax works, because the Messages component exposes ajava.util.Map interface, keyed on the message key, which means that the EL expression above references the message for the Map key orders.
Things you cannot do in JSF
Sooner or later, you are going to want to do one of the following things.
-
Output a localised label containing a placeholder in an attribute value in a Facelets view, e.g. my name in the link text of
<h:commandLink action="#{action.notify}" value="Notify Peter"/> -
Use a JSF formatter, such as a date formatter, to format a value that will be inserted into a message placeholder.
-
Insert a JSF component, such as an
h:commandLinkinto a message placeholder.
Unfortunately, these are not currently possible with the facilities in JSF, Seam and Facelets. You can either vote for javaserverfaces-spec-public issue 517 and wait for a new version of JSF 2, or you can write your own implementations.