# Replace not Format!

**URL:** <https://forums.creativeclouddeveloper.com/t/replace-not-format/7177>\
**Category:** InDesign\
**Created:** [November 27, 2023, 3:35pm UTC](https://forums.creativeclouddeveloper.com/t/replace-not-format/7177 "2023-11-27T15:35:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![oiver55](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/oiver55/32/3371_2.png) [@oiver55](https://forums.creativeclouddeveloper.com/u/oiver55)\
**Post date:** [November 27, 2023, 3:35pm UTC](https://forums.creativeclouddeveloper.com/t/replace-not-format/7177/1 "2023-11-27T15:35:39Z")

</div>

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 👇

```auto
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.

---

<div class="post-metadata">

**Author:** ![vamitul](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/vamitul/32/3075_2.png) [@vamitul](https://forums.creativeclouddeveloper.com/u/vamitul)\
**Post date:** [November 27, 2023, 5:15pm UTC](https://forums.creativeclouddeveloper.com/t/replace-not-format/7177/2 "2023-11-27T17:15:15Z")

</div>

Nope, it won’t work that way.  
The Text object in InDesign DOM holds the styling information and the text contents.  
[https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Text.html](https://www.indesignjs.de/extendscriptAPI/indesign-latest/#Text.html)  
And it kind of makes sense, when you think about it:  
“This text **has BOLD** applied.”  
“Ce texte a du GRAS appliqué.”  
How would you define the bold part in the translation?

Ideally, the response from the server should also contain the styling information.  
You could use `textFrame.textStyleRanges` to get a list of all the ranges of text that have the same formatting, then try to match them up with your response, but I don’t see how.

---

<div class="post-metadata">

**Author:** ![oiver55](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.creativeclouddeveloper.com/oiver55/32/3371_2.png) [@oiver55](https://forums.creativeclouddeveloper.com/u/oiver55)\
**Post date:** [November 27, 2023, 5:18pm UTC](https://forums.creativeclouddeveloper.com/t/replace-not-format/7177/3 "2023-11-27T17:18:57Z")

</div>

Got it, okay thanks for the clarification
