Register fo CMS events to set i18n content values

Hi,

I’m trying to use CMS event listeners with i18n enabled.
I realize both are beta features and might not be in a state that are sufficient for my use-case.

What I’d like to achieve is to automatically translate content from the default lang into the other language(s). I was thinking to:

  1. catch a preSave (or prePublish) CMS event, using cms.registerEvents
  2. take the data (or certain fields) from the entry using entry.get(‘data’)
  3. use an API service (Google translate) to translate these value(s)
  4. saving the translated values for the i18n content object using entry.get(‘data’).set(‘desc’, ‘translated desc’)

I’m able to catch and read all content data for both languages, following the docs at

The updates, however, are only saved for the original (en) content.

Here’s an example of the event handler

CMS.registerEventListener({
    name: 'preSave',
    handler: ({ entry }) => {
        const description = entry.get('data').get('description');
        const descripcion = entry.get('i18n').get('es').get('data').get('description');
        console.log("Current values", description, descripcion);

        return entry.get('i18n').get('es').get('data').set('description', 'Saving my new Spanish description');
    }
});

Results of saving my page from the CMS.


As you can see, the description is updated on the en/page.md and nothing was added on the es/page.md

For completion also the relevant parts of my config.yml, although I think this matters much.

i18n:
  structure: multiple_folders
  locales: [en, es]
  default_locale: en

collections:
  - name: 'pages'
    folder: 'src/content/pages'
    create: true
    i18n: true
    fields:
      - { name: 'title', label: 'Title', widget: 'string', i18n: true }
      - { name: 'description', label: 'Description', widget: 'text', i18n: true, required: false }

Is it possible to use these features together?
Am I using them correctly?
Or would there be any alternatives for automatically translating original CMS content using an external API?

Thanks

Also posted on Github

Hi there! Thanks for your interest in Netlify CMS. Looks like you posted your question a little while ago, but that you haven’t received a solution yet. Here’s where you might get more help:

netlifycms.org - the site houses our extensive documentation that likely contains helpful information to get you back on track.

netlify cms slack - join our friendly slack channel and chat with other cms pros to get the help you need.

GitHub Issues - think you’ve found a bug, or would like to make a feature request? Make your voice heard here. Netlify CMS is open source - PRs and other contributions are also welcome!

Stack Overflow Check StackOverflow for questions tagged “Netlify CMS” if you don’t get an answer in the Slack or the GH issues. StackOverflow reaches a worldwide audience of knowledgeable people.

Your question will be left open here for anyone to comment - but we encourage you to check out the above resources if you are still looking for a solution!

I cant even see the method registerEventListener() on my CMS interface in “netlify-cms-app”: “^2.14.8”

Weird,