RESTful API: how to handle translated text fields in views?

I am developing a RESTful API for a reservation request. There are numbers where you can request a list or details. Since the application is intended for a multilingual audience, descriptions (sometimes) are available in different languages.

Now I'm not sure how to handle these translations in the placement view. Without several languages, I would have made the β€œdescription” field or placement quite simple.

Any idea how to solve this problem?

My current idea: add a list of descriptions with culture pairs <> instead of the description field and additional subresource /descriptionsto the placement to create (POST), update (PUT) and delete (DELETE) new translations.

+3
source share
1 answer

To get views in the appropriate language, you simply set the Accept-Language HTTP header.

Inquiry:

GET /Hotel/345
Accept-Language: fr

Answer:

<Hotel>
  <Description xml:lang='fr'>Ce edifice est magnifique</Description>
</Hotel>

To perform updates, you can simply include several description elements, assuming that you are using xml as the format of your media type.

Inquiry:

PUT /Hotel/345

<Hotel>
  <Description xml:lang='en'>This building is magnificent</Description>
  <Description xml:lang='fr'>Ce edifice est magnifique</Description>
</Hotel>
+3
source

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


All Articles