I have a script that process all text in my Indesign file, however the formatting gets messed up. Here is basically how I am doing it
const documentTextframes = app.activeDocument.allPageItems.filter(item => item.constructorName === "TextFrame")
let count = 0
const intervalID = setInterval(async () => {
if (count === documentTextframes.length) clearInterval(intervalID);
var data = { "text": [`${documentTextframes[count].contents}`], "target_language": "spanish" };
const response = await fetch(url, {
method: "POST",
body: JSON.stringify(data),
headers
})
if (response.ok) {
const translatedText = await response.json();
documentTextframes[count].contents = translatedText
}
}, 2000)
I target and replace the Indesign text using
documentTextframes.[count]conents.
When I view documentTextframes.[count]conents in UDT console, the text inside doesn’t carry any formatting syntax, just plain text. So I was thinking that when I replace it the formating would remain intact, but it’s not the case.