10 Replies Latest reply on Oct 17, 2012 1:46 PM by PeteBaumgartner

    findGrep question about appliedLanguage [JS]

    PeteBaumgartner Level 1

      The script below will find all the text with the character langauge (appliedLanguage) set to "English: USA"

       

      app.findGrepPreferences = null;

      app.findGrepPreferences.appliedLanguage = "English: USA";

      var myFound = app.activeDocument.findGrep();

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

      {

             $.writeln (myFound[i].contents);

      }

       

       

      But how do I find all the text NOT set to the language  'English: USA'  ?

       

      Thanks !

        • 1. Re: findGrep question about appliedLanguage [JS]
          Trevorׅ Adobe Community Professional

          Hi Pete

           

          As far as I know it cant be done directly

          So you probably have to do a search that includes all languages and a second search for USA and remove the USA results from the all language result.

          Alternatively one can loop though all the languages except for USA.

           

          Not very efficient

           

          Trevor

          1 person found this helpful
          • 2. Re: findGrep question about appliedLanguage [JS]
            PeteBaumgartner Level 1

            Hi Trevor.

             

            You mean something like this?

             

            [CS6 JS]

            ----------

             

            var notSoughtName  = "English: USA";

             

            for (var x=0;x<app.languagesWithVendors.length;x++) {

                var thisLang = app.languagesWithVendors[x].name;

                if (notSoughtName==thisLang) continue;

               

                app.findGrepPreferences = null;

                app.findGrepPreferences.appliedLanguage = thisLang; 

                var myFound = app.activeDocument.findGrep();  

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

                {

                       $.writeln(myFound[i].contents);

                 }

            }

            • 3. Re: findGrep question about appliedLanguage [JS]
              Trevorׅ Adobe Community Professional

              Hi Pete,

               

              This is how I would have done it.

              note you put your app.findGrepPreferences = null; line in the loop, which is not a good idea.

              var myDoc = app.documents[0],
              langs = myDoc.languages.everyItem().getElements(), l = langs.length, finds = [] ;
              app.findGrepPreferences = null;
              while (l--)
              {
                  if (langs[l] != myDoc.languages.item("English: USA"))
                  {
                  app.changeGrepPreferences = app.findGrepPreferences = null;
                  $.writeln(app.findGrepPreferences.appliedLanguage=langs[l]);
                  $.writeln(langs[l].name);
                   finds[l] = [];
                   finds[l] = myDoc.findGrep();
                  }
              }
              

               

              Regards

              Trevor

              P.s. I'm Going to sleep now.

              • 4. Re: findGrep question about appliedLanguage [JS]
                Trevorׅ Adobe Community Professional

                Also note you only want to loop through the doc languages and not the app ones, that can make a big difference

                • 5. Re: findGrep question about appliedLanguage [JS]
                  Trevorׅ Adobe Community Professional

                  Made a little (important) change to my script to allow for the case that a language was entered and then its contents deleted.

                  Did this by adding the variable c.

                   

                  By the way you might be interested in my script in this thread http://forums.adobe.com/message/4587759#4587759 by #10

                   

                   

                  // Find Not language Script by Trevor http://forums.adobe.com/message/4765115#4765115
                  var myDoc = app.documents[0],
                  langs = myDoc.languages.everyItem().getElements(), l = langs.length, finds = [], c = 0, n = 0, nn ;
                  app.findGrepPreferences = null;
                  while (l--)
                  {
                      if (langs[l] != myDoc.languages.item("English: USA"))
                      {
                          app.changeGrepPreferences = app.findGrepPreferences = null;
                          app.findGrepPreferences.appliedLanguage=langs[l];
                          $.writeln (langs[l].name);
                          finds[c] = [];
                          finds[c++] = myDoc.findGrep();
                      }
                  }
                  while (n < finds.length) 
                      {
                          nn=0;
                          while (nn < finds[n].length)
                          $.writeln ("\r==============\rfinds [" + n + "][" + nn + "]\r"
                          +"appliedLanguage.name: " 
                          + finds[n][nn].appliedLanguage.name
                          +"\r*******************\rContents :------\r"
                          + finds[n][nn++].contents);
                          n++
                       }
                  
                  • 6. Re: findGrep question about appliedLanguage [JS]
                    PeteBaumgartner Level 1

                    Trevor,

                     

                    Right - that is better. And I think this has cleared up my understanding of app.languagesWithVendors as opposed to doc.languages.

                     

                    Your script worked okay on the first document which was English with a few words marked as appliedLanguage Polish, but I get an exception on the second document as it has a few paragraphs marked as 'Japanese' - apparently this document although now translated to English may have been built with a different (Japanese?) version of InDesign.

                     

                    I got an exception when setting app.findGrepPreferences.appliedLanguage='Japanese'   - so I cannot even search for this langauge setting - which is not good, as it is the very item I wished to find and clean up.

                     

                    Any thoughts?

                     

                    Thanks.

                    • 7. Re: findGrep question about appliedLanguage [JS]
                      Trevorׅ Adobe Community Professional

                      I understand the problem (I think)

                       

                      (If you have Indesign CS 5.5 or 6 there's a work around otherwise Mindsteam language lamp PRO (I think about $50) might be able to deal with it and for sure their spell check pro can deal with it as  one can add the missing languages i.e Japanese provided with the CJK or Hebrew / Arabic with the ME Version.  See the link to the other thread for a link to MindSoft)

                       

                      Just Had a good idea

                      If you want to find all not included languages do this (Make the code yourself)

                      1) Provided that the doc doesn't have conditional texts in it (there is a work around if it does) set ALL text to "Japanese" condition.

                      2) Loop through all the languages with greps and change to "none" condition.

                      3) Now you can search for the "Japanese" condition

                       

                      Pretty easy

                       

                      See some of this thread http://forums.adobe.com/message/4485105#4485105

                      for help on ways to implement this.

                       

                      Good Luck and don't forget to let me know.

                      • 8. Re: findGrep question about appliedLanguage [JS]
                        PeteBaumgartner Level 1

                        Trevor.

                         

                        Thanks, but I am not sure how this would be coded -- "Loop through all the (appliedLanguages) languages with greps and change to "none" condition

                         

                        Can you point me to an example?

                         

                        Thanks.

                        • 9. Re: findGrep question about appliedLanguage [JS]
                          Trevorׅ Adobe Community Professional

                          This should work,

                          I couldn't test it because I don't have a doc with Japanese.

                           

                          // Find Not language Script 2 by Trevor http://forums.adobe.com/message/4765115#4765115
                          var myDoc = app.documents[0],
                          langs = myDoc.languages.everyItem().getElements(), l = langs.length, myNonLanguageFinds = [];
                          app.findGrepPreferences = null;
                          myCondition = (app.activeDocument.conditions.item("Non_Language").isValid) 
                              ? app.activeDocument.conditions.item("Non_Language") 
                              : app.activeDocument.conditions.add
                              ({name: "Non_Language", indicatorColor: UIColors.YELLOW, indicatorMethod: ConditionIndicatorMethod.USE_HIGHLIGHT});
                          
                              
                          myDoc.stories.everyItem().texts.everyItem().appliedConditions = myCondition;
                          app.changeGrepPreferences = app.findGrepPreferences = null;
                          app.changeGrepPreferences.appliedConditions = [];
                          
                          while (l--)
                              {
                                app.findGrepPreferences.appliedLanguage=langs[l];
                                myDoc.changeGrep();
                              }
                          app.changeGrepPreferences = app.findGrepPreferences = null;
                          app.findGrepPreferences.appliedConditions = [myCondition];
                          myNonLanguageFinds = myDoc.findGrep(); // These are your finds
                          //myDoc.stories.everyItem().texts.everyItem().appliedConditions = []; // to Clear the Yellow Highlights un escape this line.
                          

                           

                          Just to make the post "complete" here's a link for how to add languages.

                           

                          http://blogs.adobe.com/typblography/2011/11/how-to-enable-more-languages-in-indesign-cs5-5 .html

                          Partially aplicable to CS4 and 5

                           

                          Regards

                          Trevor

                          • 10. Re: findGrep question about appliedLanguage [JS]
                            PeteBaumgartner Level 1

                            okay - I think the idea of clearing the appliedLanguage settings first, the re-establishing works best for me.

                             

                            Thanks,

                             

                            pete