Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Internationalization of string

 
sahid ul karim
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sahid",
Please check your private messages.

Dave
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could use JSTL for internationalization

See the following link for an easy example

JSTL Localizing messages
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sahid",
Please check your private messages.
Final warning before we close your account.

Dave
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic