http-accept-language

Parse Accept-Language header in Java

我与影子孤独终老i 提交于 2019-11-30 06:05:37
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? Brett Kail I would suggest using ServletRequest.getLocales() to let the container parse Accept-Language rather than trying to manage the complexity yourself. Qiang Li For the record, now it is possible with Java 8 : Locale.LanguageRange.parse() Here's an alternative way to parse the Accept-Language header which doesn't require a servlet container: String header = "en-ca,en;q=0.8,en

Parse Accept-Language header in Java

好久不见. 提交于 2019-11-29 04:48:29
问题 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? 回答1: I would suggest using ServletRequest.getLocales() to let the container parse Accept-Language rather than trying to manage the complexity yourself. 回答2: For the record, now it is possible with Java 8: Locale.LanguageRange.parse() 回答3: Here's an alternative way to parse the

How to add custom Accept-Languages to Chrome for pseudolocalization testing?

本秂侑毒 提交于 2019-11-28 04:06:44
i am testing pseudo-localization of a web-site. i can configure Internet Explorer to have custom accept languages: Click Tools , Internet Options On the General tab click Languages In the Language Preferences dialog click Add . Enter a user-defined language of qps-ploc (i.e. the Pseudo (Base) locale) Click OK Now when Internet Explorer issues an http request, the accept languages will lead with qpc-ploc : GET https://stackoverflow.com/ HTTP/1.1 Accept: application/x-ms-application, image/jpeg, application/xaml+xml, image/gif, image/pjpeg, application/x-ms-xbap, */* Accept-Language: qps-ploc,en

Python change Accept-Language using requests

帅比萌擦擦* 提交于 2019-11-28 00:09:27
问题 I'm new to python and trying to get some infos from IMDb using requests library. My code is capturing all data (e.g., movie titles) in my native language, but i would like to get them in english. How can i change the accept-language in requests to do that? 回答1: All you need to do is define your own headers: import requests url = "http://www.imdb.com/title/tt0089218/" headers = {"Accept-Language": "en-US,en;q=0.5"} r = requests.get(url, headers=headers) You can add whatever other headers you'd