Skip to main content
manuelb27477138
Inspiring
April 22, 2018
Answered

Replace English text with Spanish from a word document

  • April 22, 2018
  • 2 replies
  • 2965 views

Dears,

I need translate Indesign documents (version CC 2018) into Spanish, and I have:

1 Indesign file in English Language

1 Microsoft  Word document with the translation in spanish, but without styles. (if you considerer important for the script, I can place all the spanish word into a new Indesign document)

The both documents have one thing in common, they have the same number of paragraph.

My idea is, create a script to replace in Indesign all the English paragraph for the Spanish paragraph. Also will be nice ignore the empty paragraph in Indesign and word.

Please can you help me?

Here is an example what I mean:

INDESIGN FILE IN ENGLISH:

(paragraph number 1) Hello

(paragraph number 2) have a nice day

(paragraph number 3) Goodbay

...

WORD OR INDESIGN FILE IN SPANISH:

(paragraph number 1) Hola

(paragraph number 2) que tengas un buen día

(paragraph number 3) Adiós




Thanks so much!

This topic has been closed for replies.
Correct answer manuelb27477138

Hi TAW,

very nice plugin, but unfortunate my books need a human translator text, because are very delicate syntasis.

I was cheking your nice website, looks very professional but I can not find a solution for me.

Manuel.


Hi!

Thanks Boris for your help.

Here is the files to typeset long documents in a seconds:

Download Files

See a video

The Script:

if (app.documents.length != 2) {

    alert("2 documents must be opened!");

    exit();

    }

    var myDocEn = app.activeDocument;

    var myDocSp = app.documents[1];

    var myStoryEn = myDocEn.stories[0];

    var myStorySp = myDocSp.stories[0];

    var paraLenEn = myStoryEn.paragraphs.length;

    var paraLenSp = myStorySp.paragraphs.length;

    if(paraLenSp != paraLenEn) {

    alert("Mismatch by number of paragraphs")

    exit();

    }

    for(var i = paraLenEn-1; i >=0; i--)

    {

    myStyle = myStoryEn.paragraphs.appliedParagraphStyle;

    myStyleName = myStoryEn.paragraphs.appliedParagraphStyle.name;

    while(myStyle.parent instanceof ParagraphStyleGroup)

    {

    myStyleName = myStyle.parent.name + ":" + myStyleName;

    myStyle = myStyle.parent;

    }

    myStorySp.paragraphs.appliedParagraphStyle = getParagraphStyleByName(myStyleName, myDocSp);

    }

    alert("Done");

    function getParagraphStyleByName(myStyleName, doc)

    {

    var myParagraphStyles = doc.allParagraphStyles;

    var myParagraphStyleName, obj;

    for(var i=0; i < myParagraphStyles.length ; i++)

    {

    myParagraphStyleName = myParagraphStyles.name;

    obj = myParagraphStyles;

    while(obj.parent instanceof ParagraphStyleGroup)

    {

    myParagraphStyleName = obj.parent.name + ":" + myParagraphStyleName;

    obj = obj.parent;

    }

    if(myParagraphStyleName == myStyleName) return myParagraphStyles;

    } // for

    } // fnc

Enjoy!

2 replies

manuelb27477138
Inspiring
April 23, 2018

Just imaging, but maybe one solution can be:

1º STEP: Script to save all the English Paragraph Styles in a Array or Json. The result will be something like:

ParagraphStyle 44

ParagraphStyle 44

ParagraphStyle 66

ParagraphStyle 345

ParagraphStyle 66

ParagraphStyl 110

ParagraphStyle 66

ParagraphStyle 67

etc...

2º STEP: Place all the Spanish Word into a New indesign Document with all Paragraph Style of the English Indesign.

3º STEP: Be sure both documents have the same number of paragraph. And if not with a script or manually delete the empty carriage return.

4º STEP: on the Spanish Indesign run a Script loop and apply automatically the Array Styles generate before.

NOTE: My documents have normally 3000 paragraphs, and close to 200 paragraph styles.

Looks real solution?

TᴀW
Legend
April 23, 2018

Have a look at our product Translate | Id-Extras.com

It has a "custom dictionary" option. The custom dictionary can be as long as you want. You would need to do a little setting-up first. Create a CSV file with the English text, tab, Spanish text.

Then, in the document itself, surround the English text with [ and ] .

Translate will then look up that English text and replace with the Spanish, and create special paragraph and character styles for the Spanish.

(Or, it can simply translate the whole thing for your with Google Translate, read for post-editing).

Ariel

manuelb27477138
Inspiring
April 23, 2018

Hi TAW,

very nice plugin, but unfortunate my books need a human translator text, because are very delicate syntasis.

I was cheking your nice website, looks very professional but I can not find a solution for me.

Manuel.

Loic.Aigon
Legend
April 23, 2018

It's seems highly random to find/replace texts without a strong semantic connection between the two text sources. What would be the reference here, paragraph indeces ? Chances are that one carriage return somewhere corrupts the relation ship and that you have a non correct file.

I am not saying it's unachievable, just that it would certainly be risky to rely on such a process.

At some point you need a reliable connection. And apply styles and stuff inside InDesign or word just so a script can surely spot items may require as much time as manually copy/paste contents.

For what it's worth, you may want to use translation solutions such as Redokun : https://redokun.com/

Or build your own implementations using a xml workflow.

manuelb27477138
Inspiring
April 23, 2018

Hi Loic,

thanks for help me.

My documents have hundreds pages, then definitely I need automate this process. After do a script I can compare in Microsoft word the indesign Text with the original spanish word, then is not risk for me.

About the carriage return, is not problem because, the translation use the same text and they use the same carriage return, then I think is not risk. Also in the script is a good idea to ignore the empty carriage returns.

My english document have many differents styles, I am sure I need a script, always at the end I can manually double check everything is correct.

I was checking the scripts in your website, but can not find a script for my case. Please let me know if I am wrong.

In one point of view is very funny, because many people spend many time to translate documents. I don't like use incopy, because for the translations teams they don't like, they love word I bought some licenses of inCopy but they never use because is more complex.

I hope somebody can share a solution. I really appreciate.

thanks so much.

Community Expert
April 23, 2018

Hi Manuel,

the thing might be more complex than you think.

Let's see this simple paragraph of text in your original InDesign document:

Hello! Have a nice time, good bye!

Translation:

¡Hola! Que tengas un buen día. Adiós.

If you simply exchange the contents of the paragraph with a new contents you'll end up formatting wise with:

¡Hola! Que tengas un buen día. Adiós.

Or with:

¡Hola! Que tengas un buen día. Adiós.

Depending how you would apply the paragraph style or not. That there is something in Bold is not honored.

Or just imagine that there are GREP Styles used with the paragraph styles. Depending on the used GREP patterns they have to be rewritten for a translation or cannot be used at all…

And you never can be sure that the part that is styled differently is at the same position when translated or maybe it is even broke apart in two or more parts.

Regards,

Uwe