Score:1

How to create entity translations using JSON:API or REST API?

ph flag

I working on a headless localized site in which entities need to be synced regularly from an external source.

During the sync process, I need to create new entities and their associated translations.

I found out that JSON:API doesn't support this. Are there any workarounds to achieve this in JSON:API?

Is it something that can be achieved with the REST API? If so could you point me to some documentation?

Score:1
cn flag

Drupal's implementations of JSON:API and REST do not support creation of translated entities at this time as far as I know.

Create Entity Translations

You could try hacking a custom JSON-RPC route or JSON:API Resource, but these are not really intended for entity creation and you would have to do a lot of coding.

If possible, I would use Feeds to sync the entities and their translations. You will need to expose the content to sync in a format that Feeds supports:

  • CSV
  • XML
  • OPML
  • RSS/Atom
  • HTML/JSON

There isn't a lot of documentation on multilingual Feeds but it does work.

Create UI Translations

This wasn't in your question but just as a note. You can't create UI translations via JSON:API now, either. One fix is to export your translations as a PO file and import the file with drush:

drush locale:import my_two_letter_language_code my_path/ja.po --type=customized --override=customized
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.