Solved

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

Posted on 2006-07-13
2
1,836 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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
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 …

744 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now