开发者

Spring MVC/JSP. How to create multilanguage combo with country list?

I took advantage of the configuration as shown in this example:

http://viralpatel.net/blogs/2010/07/spring-3-mvc-int开发者_StackOverflow中文版ernationalization-i18n-localization-tutorial-example.html

Now, I would do internationalization combo with a choice of country. How can I do such a thing? (JSP and Spring MVC 3.0.5)

Please help.


You could try this:

<spring:url var="langChangeUrl" value =""/>

<form action="${langChangeUrl}" method="get">
  <select name="lang" >
    <option value="de">Deutsch</option>
    <option value="en">English</option>
   </select>
   <input type="submit" value="change"> 
</form>

I did not tested it, because I normaly used links to switch the language, so I have addepted the link based code to this form based. -- anyway even if it does not work 100% it should ilustrate the way you need to go.

Added For the (form viewpoint of usabilty critical) case that you want do display the Languages in a special languge, then you should use language files (one for each language), and <spring:message> to print them:

<spring:url var="langChangeUrl" value =""/>

<form action="${langChangeUrl}" method="get">
  <select name="lang" >
    <option value="de"><spring:message code="languageName.de"></option>
    <option value="en"><spring:message code="languageName.en"></option>
   </select>
   <input type="submit" value="change"> 
</form>

*messages_de.properties*

languageName.de=Deutsch
languageName.en=Englisch

*messages_en.properties*

languageName.de=German
languageName.en=English

messages.properties

languageName=German
languageName=English

And you need to configure spring to load the language propertie files:

<!-- Resolves localized messages*.properties files for internationalization. -->
<bean class="org.springframework.context.support.ReloadableResourceBundleMessageSource" 
        id="messageSource"
        p:basenames="WEB-INF/i18n/messages"
        p:fallbackToSystemLocale="false"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜