7 Replies Latest reply on May 30, 2018 10:15 AM by Laubender

    Automatic Index Reference Between Documents

    manuelb27477138 Level 1

      Hi everyone!

       

      I am need translate many longs documents, and I have 2 files:

      1 Indesing in English with many Index References.

      1 Indesign in Spanish without Index.

       

      ic_cloud_download_black_24dp_1x.pngHere you can Download the Indesign Files

       

      Both documents have EXACTLY the same number of paragraph. And each paragraph in the English file correspond EXACTLY with the same number paragraph in the Spanish file translate. For example:



      ENGLISH FILE:

      (PARAGRAPH 1)Article 1.

      (PARAGRAPH 2)All human beings are born free and equal in dignity and rights. They are endowed with reason and conscience and should act towards one another in a spirit of brotherhood.

      ...

      ...




      SPANISH FILE:

      (PARAGRAPH 1)Artículo 1

      (PARAGRAPH 2)Todos los seres humanos nacen libres e iguales en dignidad y derechos y, dotados como están de razón y conciencia, deben comportarse fraternalmente los unos con los otros.

      ...

      ...

       

      Like you know the InDesign Index Panel you can open in the menu:

      Window > Type & Tables > Index

       

      For create the same index in the Spanish reference I use a trick, simple copy the Reference Character GREP ⁓|  in the English Indesign and paste in the Spanish Indesign. The Character of wich I speak is this  ^

      Look the pictures:

      Screen Shot 2018-04-24 at 09.46.42.png


      Screen Shot 2018-04-24 at 10.20.46.png

       

      After copy, I paste in the more or less same word in spanish. But when you have thousdand Index References is very hard work.

      For this reason, please I would like a Script to do:

       

      1º go to the paragraph number 1 in the InDesign English copy the Index Reference Character.

       

      2º Count how many characters are from the begining of the paragraph 1 until the Index Reference Character. For example 100.

       

      3º go to the paragraph number 1 in the InDesign Spanish, and after go to the character number 100 and Paste the Index Reference Character.

       

      4º If for any reason the Spanish number of characters are short than the English (for exmple 90 instead of 100) paste at the end character of the paragraph.

       

      With this trick, will appear the same Index Reference and Structure in Spanish Indesign. And now manually I can translate very quick the words and save many hours.

       

      The result won’t be perfect because normally the words in Spanish are long than English, but is not very important the error range, because Indesign take only the number of page for build the Index.

       

       

      I appreciate any help. Thanks so much.

        • 1. Re: Automatic Index Reference Between Documents
          Michel [FRIdNGE] Level 3

          Hi,

           

          Just for comment! …

           

          You have a para in english where you have 3 times the word "house"!

          The second "house" is indexed!

           

          Now, you have the same para but in spanish (without indexed word)!

          So … according to you, what word will need be rightly indexed?

           

          (1) gato  (2) casa  (3) hombre  (4) casa  (5) caballo  (6) mar  (7) casa

           

          If you find it, you have the beginning of the solution! … But, sure!, you'll need a script and a clever scripter to achieve the game! … 

           

          Best,

          Michel, from FRIdNGE

          • 2. Re: Automatic Index Reference Between Documents
            S Hopkins Adobe Community Professional

            Hello,

            I am not too sure if what you are wanting can be done since the indexing character does not seem to be exposed to scripting. You can get a list of the index topics in the document and maybe work your way from there. The following will give you a list of the words that are referenced in the active document (the topics).

             

            set myList to {}

            tell application "Adobe InDesign CC 2018"

              tell document 1

              set theIndexes to indexes

              repeat with i from 1 to length of theIndexes

              set thisIndex to item i of theIndexes

              set theTopics to topics of thisIndex

              repeat with j from 1 to length of theTopics

              set thisTopic to item j of theTopics

              set thisText to name of thisTopic

              set end of myList to thisText

              end repeat

              end repeat

              end tell

            end tell

            myList

            • 3. Re: Automatic Index Reference Between Documents
              manuelb27477138 Level 1

              Hi S Hopkins,

              in a few days I hope publish the script.

               

              thanks

              • 4. Re: Automatic Index Reference Between Documents
                manuelb27477138 Level 1

                Hello!

                Dowload here the indesign files if you need.

                 

                How to pastes Index Markers using scripting?

                with this code we can find the index markers in the original document, but when the script pastes the index marker, it looks like this:

                 

                01.png

                 

                 

                 

                This is my original Document:

                2.png

                 

                 

                 

                Here is the script:

                var myDocEn = app.documents[0];
                var myDocSp = app.documents[1];
                
                app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
                app.findTextPreferences.findWhat = "^I";
                var found = myDocEn.findText();
                app.findTextPreferences = app.changeTextPreferences= NothingEnum.nothing;
                var foundLen = found.length;
                
                for (var i = 0; i < foundLen; i++) {
                  var item = found[i];
                  var story = item.parentStory;
                  var lastSelIP = item.insertionPoints.lastItem();
                  var paras = story.texts.itemByRange(story.insertionPoints.item(0),lastSelIP).paragraphs;
                  var currPara = story.paragraphs.item(paras.length - 1);
                  var chars = currPara.texts.itemByRange (currPara.insertionPoints.item(0), lastSelIP).characters;
                  var paraInx = paras.length-1;
                  var charInx = chars.length - 1;
                
                  var spPara = myDocSp.stories[0].paragraphs[paraInx].contents;
                  spPara = spPara.slice (0, charInx) + "~I" + spPara.slice (charInx, spPara.length);
                  myDocSp.stories[0].paragraphs[paraInx].contents = spPara;
                
                  if (i == 2) {
                    break;
                  }
                }
                
                • 5. Re: Automatic Index Reference Between Documents
                  Laubender Adobe Community Professional & MVP

                  Hi Manuel,

                  you cannot do it with property contents and assigning a string.

                  You have to either move the special character or you perhaps can duplicate the special character.

                  I never tried this with index markers.

                   

                  For duplicating text you have to use method text.duplicate() :

                  Adobe InDesign CS6 (8.0) Object Model JS: Text

                   

                  Regards,
                  Uwe

                  1 person found this helpful
                  • 6. Re: Automatic Index Reference Between Documents
                    manuelb27477138 Level 1

                    Hi Launbender, works!!

                    thanks for your advaice.

                     

                    THE SCRIPT:

                    // This script copy all index markers from one document to other. Ideal for example to translators. After run the script you will see in your Index panel all entries and you simple can translate in your language.
                    // Github files: https://github.com/firedevelop/id0000013-Adobe-InDesign-Scripts-Examples/tree/master/id0000067-Automatic-Index-Reference-Between-Documents
                    var myDocEn = app.documents[0];
                    var myDocSp = app.documents[1];
                    
                    
                    app.findTextPreferences = app.changeTextPreferences = NothingEnum.nothing;
                    app.findTextPreferences.findWhat = "^I";
                    var found = myDocEn.findText();
                    app.findTextPreferences = app.changeTextPreferences= NothingEnum.nothing;
                    var foundLen = found.length;
                    
                    
                    if (foundLen == 0) {
                      alert ("Didn't find any index markers.\nPlease check the correct document is active.");
                    }
                    
                    
                    for (var i = 0; i < foundLen; i++) {
                      var item = found[i];
                      var story = item.parentStory;
                      var lastSelIP = item.insertionPoints.lastItem();
                      var paras = story.texts.itemByRange(story.insertionPoints.item(0),lastSelIP).paragraphs;
                      var currPara = story.paragraphs.item(paras.length - 1);
                      var chars = currPara.texts.itemByRange (currPara.insertionPoints.item(0), lastSelIP).characters;
                      var paraInx = paras.length-1;
                      var enCharInx = chars.length - 1;
                      var spParaLen = myDocSp.stories[0].paragraphs[paraInx].length;
                      var spCharInx = (enCharInx <= spParaLen)? enCharInx:spParaLen - 1;
                    
                    
                      myDocEn.stories[0].paragraphs[paraInx].characters[enCharInx].duplicate (LocationOptions.BEFORE, myDocSp.stories[0].paragraphs[paraInx].characters[spCharInx]);
                    }
                    

                     

                     

                     

                    DOWNLOAD THE FILES:

                    Download

                     

                     

                    INSTRUCTIONS:

                    Open the indesign files English and Spanish.

                     

                    2º Be sure, the file English and the Spanish, have the same number of paragraph, and also the English text match with the Spanish translation. For example in the English file the paragraph number #20 have the text:

                    Article 10

                    Then, in the paragraph number #20 in the Spanish file need be the correct translation:

                    Artículo 10

                     

                    For do this Job easy, I use a simple free Code Editor like IntelliJ IDEA or Netbeans. Create 2 new files, like for example English.html and Spanish.html, now copy and paste the respective text from indesign. After do this, compare both documents, and you can see the Code Editor will show you the number of lines or paragraph, and here is easy to match manually both text, like you can see in the picture:

                     

                    Screen Shot 2018-05-30 at 13.26.50.png

                     

                    The editor will show you the comparison between the 2 files:

                    Screen Shot 2018-05-30 at 13.29.10.png

                     

                     

                    Manually you need match all lines in both files. Keep in mind it is like a mirrow, any change you do in your Code Editor, of course you need apply also in your Indesigns documents.

                     

                     

                     

                     

                    2º Optionally, if you want delete all the index marker in your second file, in my case the Spanish file, you can run this script:

                    app.activeDocument.indexes[0].topics.everyItem().remove();
                    

                     

                    3º clic on the English file, to make this document active.

                     

                    4º Run the script, and you will see from the English file into the Spanish file.

                     

                     

                    QUICK VIEW:

                     

                    English document with many index markers:

                     

                    Screen Shot 2018-05-30 at 13.34.54.png

                     

                     

                    Spanish document BEFORE run the script, without any index markers:

                    Screen Shot 2018-05-30 at 13.37.08.png

                     

                    Spanish document AFTER run the script, with all index markers:

                    Screen Shot 2018-05-30 at 13.39.10.png

                     

                    AFTER run the script you need translate manually each entry in your Spanish document.

                     

                     

                     

                     

                    SOME NOTES:

                    1º This Script was tested in a Adobe Indesign CC 2018

                    2º If you get some errors is because the number of paragraph between the both documents are not the same. Also is a good practice copy and paste your text in a New documents in indesign, just to be sure, is not other text frames of Layers the cause of the problems.

                    3º The script is working also in the case your English Paragraph text is shorter than the Spanish. In this case, the script will place the markers at the end of the paragraph.

                     

                     

                    Thanks so much. I hope you find it useful.

                    • 7. Re: Automatic Index Reference Between Documents
                      Laubender Adobe Community Professional & MVP

                      Hi Manuel,

                      thank you very much for coming back with your solution.

                       

                      Best,
                      Uwe