This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Servlets and the fly likes Getting browser language settings Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Getting browser language settings" Watch "Getting browser language settings" New topic
Author

Getting browser language settings

Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
I'm trying to localize a page according to the language settings on the users browser .... thing is I need to know how to get hold of that information. I've heard there's an attribute called accept-language ... but I'm not sure how to get hold of it .. .can anyone help??


Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
Don't worry I found the solution ... it took me so long cos I was looking at an old servlet API.
Anyway for Servlets v2.2 you need to use the HttpServletRequest.getHeaders(String) method and pass in the name of the header .. which in this case is Accept-Language. this returns an Enumeration of the languages accepted by the browser.
Rahul Mahindrakar
Ranch Hand

Joined: Jul 28, 2000
Posts: 1836
I guess you used getHeader() like in the code given below

But how do i use this information of "Accept-language". could you throw more light.

[This message has been edited by Rahul Mahindrakar (edited January 24, 2001).]
Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
First of all I used getHeaders(String) rather than getHeader(String) because as the Servlets 2.2 API says "Some headers, such as Accept-Language can be sent by clients as several headers each with a different value rather than sending the header as a comma separated list. ". So a method which returns an Enumeration rather than a String is more approriate.
What is returned is an Enumeration of strings which look something like this. "en,en-gb;q=0.7,en-us;q=0.3" which you can compare to your browsers language settings. Basically this one says. "I'd prefer English (en), my next prefernce is British English(en-gb) and my next preference is US English(en-us)."
I havn't quite completed what I'm doing yet but i'm hoping to be able to use these settings to localize a JSP according to the browser language settings rather than having the user specify a language.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting browser language settings
 
Similar Threads
SOS: Hot to get the Browser Settings
SOS: Hot to get the Browser Settings
SOS: Hot to get the Browser Settings
internationalisation problems!
Can we disable javascript in IE programatically?