Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Parse Accept-Language header in Java

The accept-language header in request is usually a long complex string -

Eg.

Accept-Language : en-ca,en;q=0.8,en-us;q=0.6,de-de;q=0.4,de;q=0.2 

Is there a simple way to parse it in java? Or a API to help me do that?

like image 276
Pushkar Avatar asked Jul 26 '11 00:07

Pushkar


People also ask

What is my accept-language header?

The Accept-Language header is information about the user's language preferences that is passed via HTTP when a document is requested. Mainstream browsers allow these language preferences to be modified by the user. The value itself is a defined by BCP 47, typically as a two or three letter language code (eg.

Is accept-language a standard HTTP header?

The Accept-Language request HTTP header advertises which languages the client is able to understand, and which locale variant is preferred. (By languages, we mean natural languages, such as English, and not programming languages.)


1 Answers

I would suggest using ServletRequest.getLocales() to let the container parse Accept-Language rather than trying to manage the complexity yourself.

like image 123
Brett Kail Avatar answered Oct 31 '22 17:10

Brett Kail