简体   繁体   中英

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-internationalization-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"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM