Справочник Пользователя для Red Hat Web Application Framework 6.1

Скачать
Страница из 230
Chapter 13. Web Applications Tutorial
169
// print in English:
System.out.println((String) message.localize(new Locale("en", "", "")));
// print in Spanish:
System.out.println((String) message.localize(new Locale("es", "", "")));
// print in French:
System.out.println((String) message.localize(new Locale("fr", "", "")));
The output will appear as follows:
This is a red wine.
Este es un vino rojo.
C’est un vin rouge.
Note
When a
key
is not found in a
ResourceBundle
, or when the
ResourceBundle
is not found at all,
the
localize(java.util.Locale)
method returns the
key
. This is done for two reasons: first, it is
more user-friendly to display the
key
than it is to display an exception or error message. Second,
this method makes it easier for a translator to see all the resources that need to be translated on a
particular page.
Caution
There are
GlobalizedMessage
constructors that do not have the base name of the
ResourceBundle
as a parameter. When these constructors are used, the base name of the
ResourceBundle
for the
current application is used. This information is retrieved from the current
ApplicationContext
.
Using these constructors is discouraged because the method is non-deterministic with regard to
changes in the application stack. For example, if an application written by one developer — e.g.
notes — runs on top of a portal application written by another developer, and it is using these
certain
GlobalizedMessage
constructors, an error can occur.
The first application is no longer the current running application, and therefore the base name of the
ResourceBundle
for the
GlobalizedMessage
s will be set incorrectly. It will be set to the base name
of the
ResourceBundle
for the Portal application.
Only use these constructors if you are sure that your application will always be at the top of the
application stack.
13.5. Globalization and Bebop
Bebop is enabled to use
GlobalizedMessage
s wherever the localizable content is displayed to the
user.
To display localized content to the user using Bebop, pass a
GlobalizedMessage
to the Bebop
widget. For example, to write a globalized
HelloWorld page using Bebop:
package com.arsdigita.helloworld;
import com.arsdigita.bebop.Label;
import com.arsdigita.bebop.Page;