Archive for November, 2007
Java Internationalization Reference
ResourceBundle and MessageFormat
try {
Locale locale = getLocale();
String rbName = getBundleName();
ResourceBundle bundle = ResourceBundle.getBundle(rbName, locale);
String retMessage = bundle.getString( key );
if ( varargs.length > 0 )
{
MessageFormat mf = new MessageFormat( retMessage, locale );
retMessage = mf.format( varargs );
//TESTING: Writing Java Unicode to UTF-8
BufferedWriter bw = new BufferedWriter( new OutputStreamWriter (new FileOutputStream(filename),"UTF-8"));
bw.write(retMessage);
bw.close();
}
} catch ( Exception e ) {
e.printStackTrace();
}
References:
I18N Messages and Logging
Provides an API that allows your Java applications to generate and log internationalized messages along with creating localized exceptions. Also provides Java annotations and an ANT task to help automatically generate language resource bundles.
http://sourceforge.net/project/showfiles.php?group_id=169460
Java internationalization with the Properties Pre-Processor
An XML-based utility for handling localized strings
http://www.javaworld.com/javaworld/jw-08-2007/jw-08-i18nproperties.html?page=4#resources
Sun Java Tutorials:
http://java.sun.com/docs/books/tutorial/information/download.html
DateFormat:
import java.util.*;
import java.text.*;
static public void showBothStyles(Locale currentLocale) {
Date today;
String result;
DateFormat formatter;
int[] styles = {
DateFormat.DEFAULT,
DateFormat.SHORT,
DateFormat.MEDIUM,
DateFormat.LONG,
DateFormat.FULL
};
System.out.println();
System.out.println("Locale: " + currentLocale.toString());
System.out.println();
today = new Date();
for (int k = 0; k < styles.length; k++) {
formatter = DateFormat.getDateTimeInstance(
styles[k], styles[k], currentLocale);
result = formatter.format(today);
System.out.println(result);
}
}
DecimalFormat:
static public void localizedFormat(String pattern, double value,
Locale loc ) {
NumberFormat nf = NumberFormat.getNumberInstance(loc);
DecimalFormat df = (DecimalFormat)nf;
df.applyPattern(pattern);
String output = df.format(value);
System.out.println(pattern + " " + output + " " + loc.toString());
}
NumberFormat:
static public void displayNumber(Locale currentLocale) {
Integer quantity = new Integer(123456);
Double amount = new Double(345987.246);
NumberFormat numberFormatter;
String quantityOut;
String amountOut;
numberFormatter = NumberFormat.getNumberInstance(currentLocale);
quantityOut = numberFormatter.format(quantity);
amountOut = numberFormatter.format(amount);
System.out.println(quantityOut + " " + currentLocale.toString());
System.out.println(amountOut + " " + currentLocale.toString());
}
static public void displayCurrency(Locale currentLocale) {
Double currency = new Double(9876543.21);
NumberFormat currencyFormatter;
String currencyOut;
currencyFormatter = NumberFormat.getCurrencyInstance(currentLocale);
currencyOut = currencyFormatter.format(currency);
System.out.println(currencyOut + " " + currentLocale.toString());
}
static public void displayPercent(Locale currentLocale) {
Double percent = new Double(0.75);
NumberFormat percentFormatter;
String percentOut;
percentFormatter = NumberFormat.getPercentInstance(currentLocale);
percentOut = percentFormatter.format(percent);
System.out.println(percentOut + " " + currentLocale.toString());
}
Simple MessageFormat:
static void displayMessage(Locale currentLocale) {
System.out.println("currentLocale = " + currentLocale.toString());
System.out.println();
ResourceBundle messages =
ResourceBundle.getBundle("MessageBundle",currentLocale);
Object[] messageArguments = {
messages.getString("planet"),
new Integer(7),
new Date()
};
MessageFormat formatter = new MessageFormat("");
formatter.setLocale(currentLocale);
formatter.applyPattern(messages.getString("template"));
String output = formatter.format(messageArguments);
System.out.println(output);
}
References:
http://www.jorendorff.com/articles/unicode/index.html
No comments
Coyote Blue by Christopher Moore (bookcrossed)
Book-crossed
http://www.bookcrossing.co
Just started reading…
Regarding bookcrossing.com:
Nowadays, most of the newly ventured and popular top-tiered websites are focusing heavily on efficiency and fun factors to attract users but missing out on returning something good to society. This bookcrossing.com has almost 600,000 users and around 4 million books registered and most of those registered books probably are being read, or bookcrossed. This is fascinating and that’s why they are so successful. As of today, I do not see them on Facebook, but adding their services to Facebook will tremendously help extend their user base to millions easily. I hope they do that soon. When I was first bookcrossed, I remember that I had a very different feeling than a book recommendation from someone I know or from newspapers. It’s something exciting and definitely something that increases my good karma
I am looking forward to being bookcrossed soon.
No commentsStruts, Tomcat, MySQL and Eclipse
1. Install tomcat
2. Install Struts framework: http://struts.apache.org/
3. download Eclipse (webtools)
4. download Eclipse Tomcat plugin:
http://www.eclipsetotale.com/tomcatPlugin.html#A3
and unzip and copy it to C:\eclipse\plugins
5. Install mysql
6. Business Logic Frameworks
http://springframework.org/
7. Data Access Frameworks
http://www.hibernate.org/
8. Tutorials:
http://struts.apache.org/2.x/docs/big-picture.html
http://struts.apache.org/primer.html
http://struts.apache.org/2.x/docs/hello-world.html
http://javaboutique.internet.com/tutorials/three/
No comments