JAVA国际化DEMO
类别: JAVA教程
目录结构:
所有的文件都在包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\", \"?ぬ?\" },
{ \"lblPassword\", \"密瘁\" },
{ \"caseName\", \"登入\" }
};
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:如果是在简体环境下测试可将zh_TW改为zn_CN
所有的文件都在包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\", \"?ぬ?\" },
{ \"lblPassword\", \"密瘁\" },
{ \"caseName\", \"登入\" }
};
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:如果是在简体环境下测试可将zh_TW改为zn_CN
- 上一篇: 一个经典的JAVA APPLET时钟程序(一)
- 下一篇: 漫谈Java中的中文问题
-= 资 源 教 程 =-
文 章 搜 索