This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Struts and the fly likes struts 2 internationalization not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts 2 internationalization not working" Watch "struts 2 internationalization not working" New topic
Author

struts 2 internationalization not working

sumit kr jain
Greenhorn

Joined: Feb 19, 2011
Posts: 2
I am developing struts 2 and spring web application which suppoerts two languages: english and hindi.
I have configured internationalization but it is not working i.e. when I change the encoding from browser, the text does not change.
I have tried to even change the locale programmatically but it still does not work

//struts.properties
struts.custom.i18n.resources=global-messages


//RegisterAction.java

public class RegisterAction extends ActionSupport {

public String execute(){
return "SUCCESS";
}

public Locale getLocale(){
return new Locale("hi");
}
}

//struts.xml

<action name="register" class="com.medics.action.RegisterAction">
<result name="SUCCESS">/Register.jsp</result>
</action>

//Register.jsp

<%@ taglib prefix="s" uri="/struts-tags" %>
<h4><s:text name="RegisterMessage"/></h4>

//global-messages.properties

hello=hello
RegisterMessage=Registration

//global-messages_hi.properties

RegisterMessage=\\u2354\\u2379\\u327\\u2367\\u2344\\u2381

struts.xml and the two messages files are in the root of the classpath

Please help me
E Robb
Ranch Hand

Joined: Aug 27, 2010
Posts: 111
Does this work?

create a properties file called testme_fr_CA.properties.
put a string in it like testme=some string.

Put this in your classes/struts.xml
<constant name="struts.custom.i18n.resources"
value="testme_fr_CA.properties"/>

Make a test page and put this in it:



Go to your test page and click on the link does it change the language?
sumit kr jain
Greenhorn

Joined: Feb 19, 2011
Posts: 2
What exactly are you doing in that code

I got an exception

There is no Action mapped for namespace /URLFOLDER and action name URACTION. - [unknown location]
E Robb
Ranch Hand

Joined: Aug 27, 2010
Posts: 111
You dont really need to map it to any action. By default I think i18 intecepter loads in the value stack. Example below is Struts 2.1. You should not have to map anything to action as long as your properties files can be found you should be good to go. This example you should have english and canadian properties files.


 
jQuery in Action, 2nd edition
 
subject: struts 2 internationalization not working
 
Similar Threads
Struts 2 struts.xml not redirecting
Struts 2 + Dynamic Struts.xml ??
Struts2 very simple validation doesn't work
global properties file
Interceptor messes up action class in Struts2