decaporg / decap-cms

A Git-based CMS for Static Site Generators
https://decapcms.org
MIT License
17.65k stars 1 forks source link

fix(i18n): allow to store the new entry in the draft after a pre save #7227

Open jmfiaschi opened 3 weeks ago

jmfiaschi commented 3 weeks ago

Summary

fixex #4729 : Today it's not possible for example to translate empty fields with external APIs with the preSave because the preSave expect to return only a datathat not contain i18n values.

With this kind of code, we should be able to update the i18n values :

CMS.registerEventListener({
  name: 'preSave',
  handler: async ({ entry }) => {
      return entry.setIn(["i18n", "it", "data", "title"], "my translated title for IT");
  }
});

The change has no regression. PreSave can return data/entry modifications.

Test plan

In Progress

Checklist

Please add a x inside each checkbox:

A picture of a cute animal (not mandatory but encouraged)