This week's book giveaway is in the JavaScript forum.
We're giving away four copies of JavaScript Promises Essentials and have Rami Sarieddine on-line!
See this thread for details.
The moose likes Struts and the fly likes Dummy needs explanation Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Dummy needs explanation" Watch "Dummy needs explanation" New topic
Author

Dummy needs explanation

Tontang Bei
Ranch Hand

Joined: Oct 21, 2006
Posts: 130
please explain to me how this flow of this internationalization example is working. The code works Allright but Im not being able to get my brain around it.
WEB-INF/classes/resource. The resource directory has 2 Properties file. One is called application.properties and has the code index.title=Welcome within it and the other is called application_de.properties and has the code index.title=Wilkommen.
(If your browser is set to English it say welcome else if its German it say Wilkommen)

In struts-config.xml, I added the line:
<message-resource parameter="resource.application" />

Below is the code for the JSP that displays it

<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html:html locale="true">
<head>
<html:base/>
<title>
<bean:message key="index.title"/>
</title>
</head>
<body>
<h2><bean:message key="index.title"/></h2>
<% out.println(request.getHeader("User-Agent")); %>
</body>
</html:html>

My question is, how is that this JSP page not knowing anything about the two application files being able to work properly? What does struts-config do to help? Im a complete newbie and this is my first Struts code so please excuse if I asked a silly question. Would like any and all explanations.
Mahesh Desai
Ranch Hand

Joined: Apr 04, 2007
Posts: 76
To implement i18n in struts app, we need to maintain multiple properties file for each language and those needs to be placed in classpath i.e. WEB-INF/classes/resource for your case. The _de suffix indicates the German locale. We need to configure default resource bundle entry in struts-config.xml file i.e. <message-resources parameter="resource.application"/>. We only need to add the default resource file to struts-config.xml. When we change the locale, the appropriate resource file (application_de.properties) will be looked up automatically.

The Struts tag <html:html locale="true"> reads the "Accept-Language" header sent by the browser, and set up a Locale object in user's session if it is not already there.


Hope this help!

Thanks,
Mahesh

---------
SCJP 1.4 | SCWCD 1.4 | SCBCD 1.3 | SCEA Part I - In Progress
Nyanas Kandhan
Ranch Hand

Joined: Jan 27, 2009
Posts: 35
For an example on Struts internationalization you can refer here.

Struts I18N using locale.
Struts Internationalization using browser settings.

regards
Struts Developer


regards,
Nyanaskandhan
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Dummy needs explanation