The 'ResourceBundle' class loads resource data according to the specified locale (if no one specified, the system locale will be used), and the localized data such as messages, lables, and images can be switched to user locale ones by this class.The codes of calling ResourceBundle is the following.
ResourceBundle wwnaviBundle = ResourceBundle.getBundle("wwnavi_rs"); <-- *"wwnavi_rs" is a property file name (see the next section).*If you call the ResourceBundle in JSP/Servlet, you have to apply the locales of HTTP requests, so the codes need changed. Please refer to Server Side Programming for more details.
#$NLS-WWNAVI 2008-05-24T20:26:09+0900 #Sat May 24 20:26:09 JST 2008 me.tree.MainPanel.8=This is node5 me.tree.MainPanel.7=This is node4
*You have to be careful about describing non-ASCII characters. You cannot describe non-ASCII characters directly in a Java property file. To describe non-ASCII characters, you have to put them in a text file and then convert it to a .properties file with the command 'native2ascii' in JDK.The next steps are for describing Japanese characters in a property file. This is a sample generated by World Wide Navi.
#$NLS-WWNAVI 2008-05-24T20:26:09+0900 #Sat May 24 20:26:09 JST 2008 me.tree.MainPanel.8=これはノード5 me.tree.MainPanel.7=これはノード4Create a property file with the 'native2ascii' command.
native2ascii -encoding UTF-8 wwnavi_rs_ja.properties.UTF-8 \ wwnavi_rs_ja.propertieswwnavi_rs_ja.properties (property file generated by the step above.)
#$NLS-WWNAVI 2008-05-24T20:26:09+0900 #Sat May 24 20:26:09 JST 2008 me.tree.MainPanel.8=\u3053\u308c\u306f\u30ce\u30fc\u30c95 me.tree.MainPanel.7=\u3053\u308c\u306f\u30ce\u30fc\u30c94
JOptionPane.showMessageDialog(null, wwnaviBundle.getString("me.tree.MainPanel.4")); <-- *Loading the message of the key 'me.tree.MainPanel.4'.
resource-bundle name (e.g. "wwnavi_rs") + "_" + language name (e.g. "ja")The default resource is a property file with the same name as the resource bundle. (*Please refer to the Java API Documentation for the details of property file naming rules.)
java -cp . me.tree.MainPanel <-- *CLASSPATH is the current directory export LANG=ja_JP.UTF-8 <-- *Change the language to Japanese. java -cp . me.tree.MainPanel <-- *CLASSPATH is the current directoryThe locations of the .properties files will be the following:
me/tree/MainPanel.class <-- *Class file wwnavi_rs.properties <-- *Default property-file wwnavi_rs_ja.properties <-- *Japanese property-file*If you call the ResourceBundle in JSP, The default CLASSPATH will be '../WEB-INF/classes' and the property files need located in it.
Go to International Programming Top