Global support for Spring Learning

Source: Internet
Author: User

International support: for applications that need to support different language Environments, you can configure all language information through independent resource files and convert different language versions.

Bean for configuring messageSource

<Bean id = "messageSource" class = "org. springframework. context. support. ResourceBundleMessageSource">
<Property name = "basenames">
<List>
<Value> messages </value>
</List>
</Property>
</Bean>

 

Define two resource files: messages_zh_CN.properties (Chinese) and messages_en_US.properties (English)

Here, messages _ ** is based on the message defined in the bean file.

// Messages_zh_CN

Userinfo = \ u5F53 \ u524D \ u7528 \ u6237 \ uFF1A [{0}] \ u767B \ u5F55 \ u65F6 \ u95F4 \ uFF1A [{1}]

// Messages_en_US.properties

Userinfo = Current loggin user: [{0}] login time: [{1}]

 

Test class

Package test2;

Import java. util. Calendar;
Import java. util. Locale;

Import org. springframework. context. ApplicationContext;
Import org. springframework. context. support. FileSystemXmlApplicationContext;

Public class testDemo {

/**
* @ Param args
*/
Public static void main (String [] args ){
// TODO Auto-generated method stub
ApplicationContext ctx = new FileSystemXmlApplicationContext ("bean. xml ");
Object [] arg = new Object [] {
"Erica", Calendar. getInstance (). getTime ()
};
String msg1 = ctx. getMessage ("userinfo", arg, Locale. getDefault ());
String msg2 = ctx. getMessage ("userinfo", arg, Locale. US );
System. out. println (msg1 );
System. out. println (msg2 );

}

 


Author: y200930690129

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.