Building multilingual pages
Next we will learn how to create a multilingual page (in English and French) using only one JSP, and display it in English by default, with a link to switch to French. We will then store the text outside the JSP, in both languages, in separate .properties
files.
How to do it…
Here are the steps to build a bilingual JSP view:
Create the JSP:
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %> <html> <body> <h1><spring:message code="home.title" /></h1> <p><spring:message code="home.intro" /></p> <p> <a href="?lang=en">English</a> | <a href="?lang=fr">French</a> </p> </body> </html>
Create the English
.properties
filesrc/main/resources/messages.properties
:home.title=Home home.intro=This is a magnificent home page, isn't it?
Create the French
.properties
filesrc/main/resources/messages_fr.properties
:home.title=Accueil home.intro=Splendide...