This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Internationalizing Strings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Internationalizing Strings" Watch "Internationalizing Strings" New topic
Author

Internationalizing Strings

Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 688

In my previous life as an object-oriented Pascal programmer for the Macintosh, we learned to internationalize by using full sentences like: "Sorry, you cannot ^1 because ^2". We learned not to use String concatenation, but to use parameter substitution instead. One problem that we solved is that different languages can have different word orders. String concatenation assumes a particular language's word order, whereas parameter substitution works for languages with a different word order.

In Pascal, the code looked like:

string2 := Param4(string1,param1,param2,param3);

In Java should I just use: String.replace(String,String) and call String.replace() once for each parameter?

Is there an easy way to do this with regular expressions or with the Pattern class? With Java 5.0, I could write my own function using varargs to take any number of parameters.

In Unicode is there a better character to indicate parameter substitution than the caret "^"?

-- Kaydell
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
If you use JDK 5 you can use format strings (e.g. the format() methods added to PrintWriter) to do this, along with a many other features. Or in JDK 1.3 or 1.4, you can use java.text.MessageFormat instead.


"I'm not back." - Bill Harding, Twister
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Internationalizing Strings
 
Similar Threads
Which is better in String or StringBuilder and in which perspectives?
Finding my way around the API docs
why java does not support multiple inheritance ?
Programming Diversion 2a: Applying a Key
BLISS, the language (was "Truely Meaningless")