0

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.

tomasz-mer
  • 3,753
  • 10
  • 50
  • 69
  • What exactly do you need? Can you provide some example of desired behaviour? – axtavt Feb 15 '11 at 15:08
  • I need a example. If a solution of the Country object is wrong. Please hint. – tomasz-mer Feb 15 '11 at 15:22
  • When he/she asked "What exactly do you need?" axtavt was saying this: "Provide a better explanation of the problem you are trying to solve". More to the point, what do you mean when you say "I would do internationalization combo with a choice of country"? Do you want the text items in the combo to change based on locale, do you want the choices in the combo to set the locale, or do you want something else? – DwB Feb 15 '11 at 16:32

1 Answers1

1

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"/>
Ralph
  • 118,862
  • 56
  • 287
  • 383
  • Is not good for me. For example - Englishman should see English, German but Germany should see England, Deutschland etc. Do you know what i mean? – tomasz-mer Feb 16 '11 at 12:53
  • @user612925: Are you shure that you want this: did you ever tyed to select your language when all langages written in Russian language (for example if you are in an internet cafe in Moskau: hint German is немецкий) – Ralph Feb 16 '11 at 12:59
  • @user612925: Anyway I have extended my answer. – Ralph Feb 16 '11 at 13:09
  • It's not like it. In one combo I choose a language. In my case it is English or German. Next on the basis of the previous selection, I would like to name the countries that look appropriate to the language. – tomasz-mer Feb 16 '11 at 13:10
  • @user612925: In this case you need a page reload between the two selections to set the language. For the second page you could use `` -- but then the second form submit must not send to ${langChangeUrl} – Ralph Feb 16 '11 at 13:15
  • Ok. And yet you could help me in this? http://stackoverflow.com/questions/5016471/spring-mvc-language-selection-in-the-combo – tomasz-mer Feb 16 '11 at 13:23