Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting browser language settings

 
Angela Poynton
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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??
 
Angela Poynton
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic