SPRINGMVC Project Internationalization (i18n) Implementation method
According to the law, every Friday night must be the time to share knowledge \ (^o^)/~, this week to talk about something, the project needs to force lattice, we International bar (* ̄rǒ ̄) ~, the project meet this kind of demand of children's shoes may not be many, but occasionally use will also compare time drops; ︿
Well, um ~, remember the beginning of software development in a very lightweight project encountered a seemingly fried days of demand, what? Internationalization? Never heard of, do not know how to play ... , Google flip a week, the gods of God paste also looked at a long time, can not solve my project needs, how to do, increase God Q harassment ~ ~ (@ ^_^ @) ~, in the official writing before the special thanks to "Erola", his original paste: http://www.cnblogs.com/ Liukemng/p/3750117.html, please worship the great God's blog before you read it (⊙▽⊙), because the great God has already put the internationalization of the centralized use of the clear, then, I will focus on the actual development of a problem I encountered ~
Our demand is actually very simple, is the customer for the convenience of crooked nuts using their system, in the interface set two for the language switch link(Chinese |en), after switching the current page function remains unchanged (that is, do not jump), the need to manually switch, The default language and location-based internationalization of the direct pass (switch the browser language location to switch the page language), of course, can not be in every view of each controller to switch the language logic in passing, it is feasible, but to write code is too redundant!
Thus, the more feasible way is based on the keyword Request page switch, suppressed for a long time, let me first ha ~,>>>just like this--->
SPRINGMVC itself is support (here is the use of spring-3.2), do not have to write code to achieve the language of the page switch, it seems very reliable, but ~, please note, because this project is not related to the intranet use of additions and deletions, so before the page is placed in the web-inf outside, like this:
(all controllers only do data processing) The problem is that the page language has been restored after point to other pages! for this question has been engaged for a long time, has not understood why, here I summed up : all the target page without controller view resolution will not apply the specified language region!!! , remember, this is important and important.
Have seen the above wisdom, the solution is actually very simple, in each target page corresponding to the controller inside plus a default page jump, so:
In this way, as long as the switch language, there will be no problem mentioned above, understand the above problems, the following step-by-step configuration:
First, you need to configure the i18n bean in the web-context.xml inside the Interceptor (just look at the second line) so that it can be applied to internationalization when each view is parsed--->
1 <mvc:interceptors>2 <Beanclass= "Org.springframework.web.servlet.i18n.LocaleChangeInterceptor" />3 <Beanclass= "Com.hst.core.spring.HttpCacheInterceptor"/>4 </mvc:interceptors>
However, add these two documents to the resources under Web-inf:
Here is the Chinese and English switch, if there are other languages, each language will write a single properties language configuration file, please note the name of the file .
Again, on the JSP page, the brow declares spring's tag library :
Again, replace the Chinese text where each previous page was displayed with the Spring message label :
Don't forget: The value of code within each tag is the corresponding key in the previous properties, and looking back at the contents of the properties is clear ~--->
So, the last step, but also the simplest step: the interface to add link, generally only need to add in the main JSP can be, the location of the HA ~, tell you a little secret, you just need to be OK (~ ̄▽ ̄) ~
Ok~ finally finished ~, sharing knowledge is happy, I wish you a happy weekend happyヾ (O???)? ヾ
====== Small Suggestion ======
Properties file inside the Chinese default only display Unicode encoding, if there is a large number of text to be added, it is recommended to use the Properties Editor plugin, eclipse install this plugin please refer to: http://www.cnblogs.com/ Panie2015/p/5637847.html
SPRINGMVC Project Internationalization (i18n) Implementation method