I’m using a translation plugin (https://www.datocms.com/marketplace/plugins/i/datocms-plugin-translate-fields) to provide localized translations for all records and pages. However, since there are many pages, manually clicking the translate button for each field with localization enabled is not feasible. I want to automate this process by writing a script to trigger this action programmatically. How can I access or trigger the translation functionality using something like datocms/cma-client-node
(to update and manage content) or any other packages?
Hi @boomika08082002,
Sorry that this is such a difficult process right now Our own @m.finamor is currently working on a plugin solution that will hopefully make bulk translations easier. It should be available within the week, and we’ll announce it here too when that happens.
If you need it sooner than that, though, the basic outline would be something like this using the CMA:
- List records with the CMA, with nested blocks enabled (if you have them)
- If you have a lot of records, you may need to deal with pagination
- For each record:
- For each field, make a call to an external translation API. This part is up to you, unfortunately, but you can take a look at that plugin’s source code and adapters for OpenAI, Yandex, and DeepL to see how @devoorhoede did it (thank you for sharing that with the community!)
- Update the record by providing the translated fields in the new locales. You can either leave any unchanged fields out of the request altogether, or just provide the same data that you got back from the “list” operation earlier.
Please test this in a sandbox environment first, away from your production DatoCMS data and visitor-facing website. It can be dangerous if you update the records incorrectly.
Sorry it’s such a hassle. Hopefully the new plugin will make this easier, soon
Thank you for the detailed suggestion! I agree that the approach mentioned seems a bit tedious and might involve some risks. It’s definitely better for us to wait for the plugin solution by @m.finamor. We’re hopeful that it will be available by the first week of 2025. Thanks again for your guidance, and we look forward to the upcoming update!
Happy new year! The initial version of @m.finamor plugin’s has been released:
https://www.datocms.com/marketplace/plugins/i/datocms-plugin-ai-translations
It can translate entire records at once (though not entire models yet). If you’d like to give it a try, here it is… please share any feedback with us