Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Set browser language via a dropdown in javascript or via JSTL?

Posted on 2006-07-13
2
Medium Priority
?
1,853 Views
Last Modified: 2013-11-24
Is it possible to set a users browser language through javascript or using the JSTL?

I have a webapp that has been internationalized.  This works fine for english/spanish/french.

I want to be able to change the displayed language on the fly via a dropdown.  This dropdown would contain (english, spanish, french) and upon clicking one of these, the page would refresh and the new browser language would be set.

Is there a way to do this?  Can I take advantage of the app already being internationalized and change the language "on the fly" so to speak?

Thanks.
0
Comment
Question by:csciguy81
2 Comments
 
LVL 6

Accepted Solution

by:
liviutudor earned 1500 total points
ID: 17100742
well the best way -- in my humble opinion -- is to have a session property for the user language. Then use a dropdown menu on each page so when the user changes it, you take another trip to the server and submit the new language value, store this in the session so then every time the user requests a page, you can check out the language s/he selected last and display the page using that language.
In other words, do it server side.
0
 

Author Comment

by:csciguy81
ID: 17102988
I ended up storing it in the session, but not doing the processing server side.  

Set an attribute called "locale" in the session, based on the users dropdown selection.

Run this on my page, and it works fine.
<%String language="";
if((String)session.getAttribute("locale")!=null){
      language=(String)session.getAttribute("locale");
}else{
      language="en";
}
%>
<fmt:setLocale value="<%=language%>"/>
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Loops Section Overview

971 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question