• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Getting browser language settings

 
Ranch Hand
Posts: 3143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic