Two Laptop Bag*
The moose likes Struts and the fly likes Internationalization Problen Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Internationalization Problen" Watch "Internationalization Problen" New topic
Author

Internationalization Problen

Anand Nuchchi
Greenhorn

Joined: Apr 15, 2006
Posts: 27
Hi all,
In my application am using struts framework, to build internationalization.
The Appln will be started by taking the computer Locale like ex:en_US(english). And the Home Page wil allow the user to choose any lang. Like Chinese or German in the drop down menu. If the user selects the Chinese lang. then rest of the appl. should display in chinese lang. only.
For this mine code is.....
----------This code wil go in home.jsp ------
<html:form action="/Home" method="post">

<nobr><select name="tname" style="font-size:0.8em;" tabindex="1" class="button">

<option value="en" ><bean:message key="en"/></option>
<option value="de" ><bean:message key="de"/></option>
<option value="zh" ><bean:message key="zh"/></option>
</select>
</nobr>

<html:submit><bean:message key="selectlang"/></html:submit>

</html:form>


------This code wil go in homeForm.java ------
String tname=null;

public String getTname() {
return (this.tname);
}

public void setTname(String tname) {
this.tname = tname;
}

------This code wil go in homeAction.java ------

if(rEBHomeSearchForm.getTname()==null)
{
session.setAttribute("org.apache.struts.action.LOCALE", currentLocale.toString());
}
// For English Language selection
else if(rEBHomeSearchForm.getTname().equals("en"))
{
session.setAttribute("org.apache.struts.action.LOCALE", new Locale("en"));
}
// For Chinese language selection
{
session.setAttribute("org.apache.struts.action.LOCALE", new Locale("zh"));
}



// For German Language selection
else if(rEBHomeSearchForm.getTname().equals("de"))
{
session.setAttribute("org.apache.struts.action.LOCALE", new Locale("de"));
}
========
The problem is, am not able to mentain the session value of particular lang assigned by the user. If the user selects the chinese then the home wil be display but for next further pages its again displaying in english only.
Please tel me how to rectify my code.
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
Couple of things

- Replace "org.apache.struts.action.LOCALE" with Globals.LOCALE_KEY (though it's not critical)
- Try configuring controller not to process setting locale.
<controller ... locale="false" />

Try debugging to see when the locale is reset and where it's happening if the above option didn't work.
Anand Nuchchi
Greenhorn

Joined: Apr 15, 2006
Posts: 27
Yes, I tried for Global.LOCALE_KEY but its showing error.
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
Try putting the following in your struts-config.xml file.

<controller locale="false" />

This will tell Struts not to set the locale. I assume you'd want to do this since you're already setting it yourself.
[ July 31, 2006: Message edited by: Merrill Higginson ]

Merrill
Consultant, Sima Solutions
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
It's Globals.LOCALE_KEY not Global.LOCALE_KEY. Try the controller option and see if it works otherwise you need to find out when the session attribute is updated. You can write a listener to log the updates (though it's long shot and will not be required
Anand Nuchchi
Greenhorn

Joined: Apr 15, 2006
Posts: 27
Hi Purushothamann,
I got the solution.
Thanks a lot!!!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Internationalization Problen