1

I have a RESTful service that returns an enum.

I was pondering whether to return integers or strings for an enum value, when it occurred to me that returning a string would depend on the locale of the client.

So how should you handle localisation in REST? Is locale part of conneg?

GazTheDestroyer
  • 20,108
  • 7
  • 67
  • 101

1 Answers1

8

Localisation is part of content negotiation, and language preferences are specified using the Accept-Language header (RFC).

The RFC is quite strict about what the service is allowed to return here — for instance, if no header is sent, then you may choose any language, but if a header is included, then you may only return one of the requested languages, and are not allowed to fall back to a different language.

In other words, if a resource is only available in English, then a resource requested with Accept-Language: de should return 406 Unacceptable rather than default to presenting the English version.

Other alternatives that don't use the specification but do allow for fallback options are discussed in a couple of other questions (8204816, 7892502).

Community
  • 1
  • 1
cmbuckley
  • 36,905
  • 8
  • 73
  • 90
  • 1
    As of RFC7231, [this is no longer the case](https://tools.ietf.org/html/rfc7231#section-5.3.5). Indeed, treating the response as if it was not subject to content negotiation (and returning English by default) is preferred over sending a 406, as not doing so "can prevent users from accessing content that they might be able to use". – followben Jul 20 '16 at 03:32