Spring Internationalization support

Source: Internet
Author: User
Tags getmessage locale

Spring's support for internationalization is a new feature added to the Beanfactory subinterface ApplicationContext, mainly because the ApplicationContext interface inherits the Messagesource interface. The GetMessage (String code,object[] Obj,locale Locale) method of the Messagesource interface is used for internationalization support.

In spring's support for internationalization we need to configure in the context of the application:

<bean id= "Messagesource" class= "Org.springframework.context.support.RegourceBundleMessageSource" >

<property name= "Basenames" >

<list>

<value>message</value>//indicates that our resource file basename is a message, the default path of the resource file is under the SRC path, if we want to put the resource file under test, then <value >test/message</value>

</list>

</property>

</bean>

Create a resource file message_zh_cn.properties hello= Hello {0}

Message_en_us.properties hello=hello{0}


We can go through ApplicationContext ac=new classpathxmlapplicationcontext (...);

String hello=ac.getmessage ("Hello", New string[]{"HI"},locale.getdefault (Category.format));

You can get the value of hello in this locale



Spring Internationalization support

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.