Java International demo

Source: Internet
Author: User
Directory structure:
All 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", "zookeeper "},
{"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: Change zh_tw to zn_cn for testing in a simplified environment.
Author's blog:Http://blog.csdn.net/li_mohao/

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.