--
PedroRio - 18 Jun 2010
Internationalization (i18N)
To create and use multi-language messages in XWC Components and in XVW viewers the following must be made.
Steps:
1) Create an Interface/Class with a set of N public static final fields, which return an instance of XUILocalizedMessage and give each of them a name, like in the following example (the example assumes a ViewerMessages Interface)
public static final XUILocalizedMessage BUILDER_ELAPSED_TIME =
new XUILocalizedMessage( ViewersMessages.class.getName(), "TIME_BUILDER" );
public static final XUILocalizedMessage BUILDER_PROCESSING =
new XUILocalizedMessage( ViewersMessages.class.getName(), "BUILDER_MESSAGE" );
When creating a new
XUILocalizedMessage, two parameters must be passed, the
first is the name of the current class and the
second, an identifier for the message
2) Create a ViewerMessages.properties file (the name of the properties file, must match the name of the class/interface) and write the translations for messages in the default application language, for the above example it would be something like:
TIME_BUILDER = Time that will take to build
BUILDER_MESSAGE = Builder is processing
3 ) For each of the available languages in your application create
ViewerMessages_pt.properties,
ViewerMessages_es.properties,
ViewerMessages_XX.properties files so that the translations for other languages are available. The
ViewerMessages_pt.properties would be something like the following.
TIME_BUILDER = Tempo para terminar o build
BUILDER_MESSAGE = Builder está a processar
Usage in a XWC Component
When developing a custom component, textual content may need to be printed. Instead of making something like this:
StringBuffer b = new StringBuffer();
b.append(" Builder is processing ");
// processing
One can use the already defined messages with the following code:
StringBuffer b = new StringBuffer();
b.append(ViewerMessages.BUILDER_ELAPSED_TIME.toString());
Usage in a XVW Viewer
To use localization in a XVW Viewer an additional step must be performed. In the XML definition of the viewer in the xvw:viewer element the localizationClass attribute must be filled with the fully qualified name of a class which defines the messages (like
ViewerMessages in the above example)
<xvw:viewer beanClass="" beanId="viewBean" localizationClasses='pt.itds.project.localization.ViewerMessages>
</xvw:viewer>
And, to use a message in a Menu component, one would declare the component as
<xvw:menu text='@{BUILDER_ELAPSED_TIME}'/>
To continue