Specifying the locale for the HTTP request / response

I have a ReSTful web service that needs to parse locale-dependent data from a request. This data can be either in an XML element or in part of a query string. Is there any way to determine in which locale the data is sent (and by extension the locale to which the response should be sent)?

One option is to simply tell clients the locale where all requests should be sent. The friendly option seems to allow the client to specify the locale.

I thought:

a) using the accept http header to encode this information.

b) using the xml: lang attribute for XML POST and an additional field for query strings (e.g. ... & locale = en-GB)

http://www.w3.org/International/questions/qa-accept-lang-locales warns of restrictions on the use of the accept-language header, but most of the warnings seem to be centered around requests coming from browsers. In my case, the requests will be come from other applications.

All tips are greatly appreciated!

+4
source share
2 answers

Your immediate choice is Accept-Language and probably Accept-Charset. Another option is to use a database that maps the client's IP address to a geographic location (as far as possible). These databases have become pretty good. I think, but they are usually not free (you have to pay).

+7
source

An accurate and thorough discussion of the w3.org topic is given here . Summary: you can use the language as a first guess, but make sure that your client can correct the local settings that you get from this, as this may be wrong.

+3
source

Source: https://habr.com/ru/post/1304401/


All Articles