Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Internationalization of web service

 
Johannes Thorén
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm facing a problem where i have to internationalize a web service.

I have x number of .jsp files, where i present for example:

"Enter your surname:"
"Enter your e-mail".. and so on.

And i wonder if there is any simple way to change language by for example clicking a button.
The krux is that i have to use the same file, so I'm thinking, maybe there is a way to have 2 files with properties, same name of the properties
but the value is on 2 different language, and then when you click the button you simply read the properties from one file or the other?

Is this possible, if so, how do i implement it? :-)

Kind regards,
Drace
 
Kumaravadivel Subramani
Ranch Hand
Posts: 171
Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may have two different property files to be served based on the language change. The same behavior is being followed in frameworks like struts. It would not be a recommendation to use same file for different language.
 
Johannes Thorén
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kumaravadivel Subramani wrote:You may have two different property files to be served based on the language change. The same behavior is being followed in frameworks like struts. It would not be a recommendation to use same file for different language.


I found a solution using propertyfiles.
Awesome! :-)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the <fmt:message> JSTL tag.
 
Johannes Thorén
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed the language problem, but one issue still remains. Now when i change the language using JSTL it changes for the webpage that i'm on. How can i make the language selection to be implementet on every page, when i brows to other pages on the same site?

I guess there must be some kind of way to send a value between pages and when the next page is about to load, checks "what language?".

Kind Regards,
Johannes
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Store the language selection in the user's session.
 
Johannes Thorén
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Store the language selection in the user's session.


Could you be more specific please, I'm a total newcommer on this area. The code i have in my JSP-files right now are:






And then everything with dynamic language presented like:


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right now, it looks like you are getting the language value from the parameters. Rather, once you know it, store and retrieve it from the session
 
Johannes Thorén
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Right now, it looks like you are getting the language value from the parameters. Rather, once you know it, store and retrieve it from the session


Is that possible to do in a Spring project, the language works perfect between pages, exept for my interceptor. Since that url is set in an xml file.

How can i reach the session to save it?

Kind regards,
Drace
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic