Java Reference
In-Depth Information
append the
.src
suffix to the key; for the alternate text, use the
.alt
suffix.
For example:
stripesbook.action.MessageComposeActionBean.addTo.src=images/fr/arrow.png
stripesbook.action.MessageComposeActionBean.addTo.alt=Ajouter
11.3
Switching Between Languages
Although the application now automatically appears in French if that's
the user's preferred language, we might also want to let the user choose
the language directly in the application. This could be a link at the bot-
the user from having to change the browser's settings and caters to
those bilingual users who might feel like switching languages accord-
ing to their mood.
One way to implement this feature is to use a request parameter that
tells the application what locale to use, such as
locale=fr
. This value is
stored in the session and used until the user switches the language
again.
To make this possible, we'll need an extension to the Stripes module
called the locale picker. On each request, Stripes uses an implementa-
tion of the
LocalePicker
interface to determine the locale and character
encoding:
public interface
LocalePicker
extends
ConfigurableComponent {
public
Locale pickLocale(HttpServletRequest request);
public
String pickCharacterEncoding(HttpServletRequest request,
Locale locale);
}
The default implementation looks in the request for a list of preferred
locales and compares it to the list of locales supported by the applica-
tion, as we discussed earlier. We can extend the default class and add
the behavior of first looking for the
locale=
parameter in the request and
in the session before falling back to the behavior of the parent class.
4.
Of course, if the application became available in more than two languages, we'd use
something else: several links, a select box, or what have you. Right now we'll stick to a
single link that switches between English and French.
Search WWH ::
Custom Search