[Spring] Spring MVC for internationalization/multi-language

Source: Internet
Author: User
Tags getmessage i18n locale

1. Add Multilingual Files *.properties

F64_en_en.properties details are as follows:

f60_g00_m100= pleaseselect data. f60_g00_m101=are you sure do want to delete? f60_g00_m102=the data is changed. Does want to save it?

2. Configuring the SPRINGMVC configuration file

<BeanID= "Messagesource"class= "Org.springframework.context.support.ResourceBundleMessageSource">        < Propertyname= "Basenames">            <List>
<!--Follow-up development requires an internationalized module to be added here-- <value>i18n. Example</value> </List> </ Property> < Propertyname= "Defaultencoding"value= "UTF-8" /> < Propertyname= "Usecodeasdefaultmessage"value= "true" /></Bean><!--set up an internationalized multi-language for cookie interpreter analysis Settings -<Beanclass= "Org.springframework.web.servlet.i18n.LocaleChangeInterceptor" /><BeanID= "Localeresolver"class= "Org.springframework.web.servlet.i18n.CookieLocaleResolver"> < Propertyname= "Cookiemaxage"value= "315360000" /> < Propertyname= "Defaultlocale"value= "En_en" /> < Propertyname= "CookieName"value= "Language">
</ Property></Bean>

3. Modify the language of the running environment after successful login

 //  if  ("EN" .equals (Logonuser.getlanguage ()) {Locale Localeen  = new  Locale (" en "," en " else  if  ("JA" .equals (Logonuser.getlanguage ()))    {Locale LOCALEJP  = new  Locale ("ja", "JP"  else   {Locale Localeen  = new  Locale ("en", "en"  

4. Define methods for acquiring classical Chinese content

protected string GetMessage (String code,object ... params)        {return  messagesource.getmessage (code, params, Localecontextholder.getlocale ());}

5. Acquisition of Classical Chinese content

String title = GetMessage ("rf64_l001");

[Spring] Spring MVC for internationalization/multi-language

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.