Tall Blondes from Mysore Zoo., originally uploaded by appunni.
This is one of the most exciting scenes that I saw at Mysore Zoo. These Tall Blonds reminds me of the stunning tennis star Maria Sharapova.
Tall Blondes from Mysore Zoo., originally uploaded by appunni.
This is one of the most exciting scenes that I saw at Mysore Zoo. These Tall Blonds reminds me of the stunning tennis star Maria Sharapova.
Did you all know that there is a website for Bangalore police from where you can submit your grievances online. How many times have you come across law breakers in Bangalore and wished to raise your voice against them. Laziness or lack of time might have kept you away from walking to the police station and lodging a complaint. Now you can do that from your home or office by just filling an online form. Bookmark this website and next time when you come across a law breaker, register a complaint. Cm’on friends, lets do our bit to make Bangalore a better place for us to live. I have come across many bad experiences from auto drivers in Bangalore. Today I had another one, a very bad one. I have registered a complaint against the auto driver through this web site. Hoping that police will take action on my complaint.
While developing Java programs which uses ResourceBundle to load properties files, a common pratice is to put all your English locale content into the default properties file XXX.properties. Till recently I did’nt know that it is important to ship your English locale files in XXX_en.properties file also. Problem arises when the user of your program runs the
program with a different locale other than English as platform default locale.
Let’s try one example to make the problem clear.
Consider the following program,
import java.util.*;
class TestBundle {
public static void main(String args[])
{
String baseName = “MyResources”;
try {
// Get the resource bundle for a specific locale
ResourceBundle rb = ResourceBundle.getBundle(baseName, Locale.ENGLISH);
String key = “hello”;
String s = rb.getString(key);
System.out.println(s);
key = “bye”;
s = rb.getString(key);
System.out.println(s);
} catch (MissingResourceException e) {
e.printStackTrace();
}
}
}
This is a standard program used to load a resource “MyResource_en.properties”.
My expectation is that if “MyResource_en.properties” is not there the program will load
“MyResource.properties”.
We will create two properties file, “MyResource_fr.properties” and “MyResource.properties”.
MyResources.properties:
hello=Hello
bye=Goodbye
MyResources_fr.properties:
hello=Bonjour
bye=Au Revoir
Now lets run our program in the following way,
java -Duser.language=fr TestBundle
We expect Hello and Goodbye to get printed.
Oops!! but it is actually Bonjour and Au Revoir that get printed.
The secret lies in the way ResourceBundle looks for files. ResourceBundle.getBundle generates a sequence of names to find the correct translation. To explain in a simplified way, if we assume that the server or machine on which your program runs uses French locale as default locale and the your program looks up English locale, following names will be generated,
MyResource_en.propertes -> User/Program locale.
MyResource_fr.properties -> The server/machine locale.
MyResource.properties -> Default if nothing matches.
MyResource_en.propertes does not exist, so MyResource_fr.propertes gets loaded.
A more detailed explanation of the file lookup order can be found in JavaDoc.
In Solaris platform, you can set the machine default locale to fr in the following way,
In bash prompt type,
LANG=fr
LC_ALL=fr
export LANG
export LC_ALL
In windows platform use the -D option.
So the important learning is, better ship your english content both XXX.properties and XXX_en.properties files rather than tracing bugs on weekends.