Java Internationalization Demo
Last Update:2017-02-28
Source: Internet
Author: User
Directory structure:
all the files are under the package demo.
Mllogin.java
Package demo;
import Java.util.ListResourceBundle;
public class Mllogin extends ListResourceBundle
{
public Mllogin ()
{
}
static final java.lang.object[][] contents = {
{"Lblusername", "Lblusername"},
{"Lblpassword", "Lblusername"},
{"Casename", "Lblusername"}
};
public java.lang.object[][] getcontents () {
return contents;
}
}
applicationresource_zh_tw.properties
error.requiredfield=the field is required to save
label.phone=\u96fb\u8a71
label.name=\u540d\u5b57
Mllogin_zh_tw.java
Package demo;
import Java.util.ListResourceBundle;
public class MLLOGIN_ZH_TW extends ListResourceBundle
{
public mllogin_zh_tw ()
{
}
static final java.lang.object[][] contents = {
{"Lblusername", "Account"},
{"Lblpassword", "Password"},
{"Casename", "Login"}
};
public java.lang.object[][] getcontents () {
return contents;
}
}
Formatexample.java
Package demo;
import Java.util.ResourceBundle;
import Java.util.Locale;
import Java.text.MessageFormat;
/**
*
* @author Limohao
*/
public class Formatexample {
/** creates a new instance of Formatexample * *
public formatexample () {
}
public static void Main (String [] args) {
String ss= "demo. Applicationresource ";
ResourceBundle Bundle=resourcebundle.getbundle (ss);
String requiredfieldmessage =bundle.getstring ("Error.requiredfield");
String [] messageargs=new string[1];
messageargs[0]=bundle.getstring ("Label.name");
String Formatnamemessage=messageformat.format (Requiredfieldmessage,messageargs);
System.out.println (formatnamemessage);
messageargs[0]=bundle.getstring ("Label.phone");
String Formatphonemessage=messageformat.format (Requiredfieldmessage,messageargs);
System.out.println (formatphonemessage);
try{
//Class test=class.forname ("Demo.mllogin");
//String cname=test.getname ();
String cname= "Demo. Mllogin ";
bundle=bundle.getbundle (CNAME);
String temp=bundle.getstring ("Lblusername");
System.out.println (temp);
}catch (Exception e) {
E.printstacktrace ();
}
}
}
Note: If you are testing in a simplified environment, you can change the ZH_TW to ZN_CN