Reputation: 3930
I took advantage of the configuration as shown in this example:
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.
Upvotes: 0
Views: 6317
Reputation: 120811
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"/>
Upvotes: 1