adr/2021_06_24_api_content_internationalization.md
A big chunk of resources available in Sylius have some part locale aware. Product descriptions, names of payment or shipping methods should be translated to the customer to provide the best user experience. Right now most of the resources are returned with all available translations in the store and proper localization of content is left to the frontend developers. What is more, this solution is not consistent, as some endpoints already embeds some part of translatables in them. We should provide clear, easy to use and consistent way of handling customer locales.
We can update all not coherent at the moment resources to always returning all possible translations and leave it to the fronted to render proper one.
As researched by @pamil, we can take advantage of JSON-LD processor, return data according to its specification and leave proper data structure to the JSON-LD processor.
Ref.
This approach goes the most side to side with the default Sylius architecture. This is the way, how we treat Sylius resources internally for most of the cases. It is supported out-of-the-box and can be easily achieved. By default all resources are served in a default locale of a channel (or Administrator in terms of admin panel). This may fallback to app wise default locale.
The first approach should be used in admin section of API, while the third one should be used in shop section. This way, we will receive best of both worlds with the minimal effort. It is worth mentioning that Sylius have two distinguish entry points to API - admin and shop. They are concerned about different things and resolves different problems. Unified view of a product in the shop will make it easy and straightforward to build product pages. At the same time all translation approach should be used in admin to provide full control over "translation" resource - as we should treat them. Therefore, every resource translation should be linked to the main resource through IRI. Each of these translation resource may be a subject of all CRUD operations accessible throughout HTTP Verbs.