aspose file tools*
The moose likes JSP and the fly likes Internationalization of string Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Internationalization of string" Watch "Internationalization of string" New topic
Author

Internationalization of string

sahid ul karim
Greenhorn

Joined: Jun 06, 2007
Posts: 20
In my application,some strings are hard-coded in jsp-scriplets and those are used to display to client as messages ( like "'ID' parameter does not exist" ).But if i want to make my application as internationalized standard, i have to remove all hard-coded string from my jsp-scriplets.Can anybody tell me hw to do this,what architecture should i follow?
ex:-
<JSP_SCRIPTLET>
String activityID = request.getParameter("ID");
String eventType = request.getParameter("TYPE");
String url = "";

;
if (activityID == null) {

throw new Exception("'ID' parameter does not exist");
}

if (eventType == null) {

throw new Exception ("'TYPE' parameter does not exist");
}


if (eventType.equals("AT1")||eventType.equals("AT2")) {

String recurring = request.getParameter("RE");
String level = request.getParameter("LV");
String userName = request.getParameter("userName");
String readOnly = request.getParameter("RO");
String attendee = request.getParameter("AT");
String acceptable = request.getParameter("AC");

if (recurring == null) {

throw new Exception("Recurring 'RE' parameter does not exist");

}

if (level == null) {

throw new Exception("Level 'LV' parameter does not exist");

}

</JSP_SCRIPTLET>
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"sahid",
Please check your private messages.

Dave
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
What Strings are you trying to internationalize?

By the way, it is considered very bad practice to catch "Exception". You should catch particular exceptions not the general "Exception"
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
You could use JSTL for internationalization

See the following link for an easy example

JSTL Localizing messages


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
Again, which Strings? The only Strings I see are the name part of the name/value pairs and they will always be in a single language (usually English).

Internationalization has to do with the display of Strings in various languages. JSTL has tags to accomplish this, but I do not see any Strings that are send to the Output Stream
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
Please do not tell me that you are displaying back to the client the text that you have placed into the Exception that you have created?

Throwing a general Exception and then catching this general Exception is a very bad way of handling a case that is really not an Exception. Where are you catching this Exception?

If you explain what you are doing I am sure there is a better way of doing it. It sounds like most of your logic is in the JSP
sahid ul karim
Greenhorn

Joined: Jun 06, 2007
Posts: 20
My query is regarding internationalization. I want to display those exception message in different language.Ex.- 'ID' parameter does not exist" is displaying when id in not present in the list.But if i want to display in in German or Spanish, then again i have to change those code.What is the better way to do internationalization?
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

"sahid",
Please check your private messages.
Final warning before we close your account.

Dave
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
Both Struts and JSTL can help you with this, but it would be very hard for you to use them because of the way you are handling the Exception. If you still want to handle the "Exception" the way you are currently doing it, then look ino using a ResourceBundle to look up the error message. Of course, you would need to have a Locale handy to look up the internationalized message. I wish I could be of more help but I cannot tell where you are consuming the Exception and its associated String message.

You should start by looking at the J2EE tutorial from Sun regarding internationalization
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Internationalization of string