Using a Separate Page per Locale
The JSTL I18N actions make it easy to use the same page for all locales. But as described earlier, sometimes it’s better to use a separate page per locale. The poll example uses this approach for the detailed description of the question.
As shown in Example 14-1, the
poll.jsp page uses a resource bundle with the
base name pages to hold the name of the details
page for each locale. Here’s how the
pages_sv.properties looks:
details_page=details_sv.jsp
This makes it possible to use the
<fmt:message> action to dynamically generate
a link to a separate page for each locale:
<a href="<fmt:message key="details_page" bundle="${pagesBundle}" />">
<fmt:message key="question" />
</a>Here, I specify the bundle for the
<fmt:message> action explicitly since the
pages bundle is not the default bundle.
All that remains is to create a page per supported locale. Example 14-4 shows the Swedish page.
<%@ page contentType="text/html" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head>
<title>
<fmt:message key="title" />
</title>
</head>
<body bgcolor="yellow">
<h1>
<font color="blue">
<fmt:message key="question" /> </font> </h1> <font color="blue"> Idag introduceras nya teknologier och affärsideer mycket snabbt. Produkter som såg ut som givna vinstbringare igår är idag så vanliga att det inte går att tjäna pengar på dem, med flera versioner tillgängliga gratis som Open Source. En affärsplan baserad ...Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access