The code provided by @florianmrz works great, but I encountered an issue when I wanted to update an already existing entry and add a localization to it. Specifically, the localizations field would just stay empty.
I eventually figured out that using the Query Engine API instead resolved the problem for me. Here’s the modified code snippet using the Query Engine API to update an existing entry:
// (This exact logic does not work with the Entity Service API)
const updatedMainEntry = await strapi.query('api::item.item').update({
where: { id },
data: {
localizations: [localizedEntry.id],
},
populate: ['localizations'],
});
I hope this helps anyone who might come across this post!