4 Replies Latest reply on Sep 7, 2013 2:50 AM by virender_CTS

    Find and replace month names

    virender_CTS

      Dear all, I have a few eps files in which month-year format is written like May-12, June-13 etc. I want to change May to Mai, June to Juin etc.

       

      Virender

       

      var myDoc = app.activeDocument;

      for (i = 0; i < myDoc.textFrames.length; i++ )

      {

           var textArt = myDoc.textFrames[i];

           for (j =0; j < textArt.words.length; j++ )

           {

            var word = textArt.words[j];

           

           switch (word.contents)

           {

           case "May-\d\d":    // please advise here

                  word.contents = "Mai";

              break;

       

           case "Mar-\d\d":

                  word.contents = "Mrz";

              break;

       

           case "June-\d\d":

                  word.contents = "Juin";

              break;

       

           }

          }

      }

       

       

      alert("Done");

        • 1. Re: Find and replace month names
          pixxxel schubser Level 5

          Do you mean something like this?

           

          Replace_Monthnames.png

           

           

          // ReplaceMonthNames.jsx
          // ersetzt im obersten Textframe "May-" und "June-" durch "Mai-" und "Juin"
          
          
          var aDoc = app.activeDocument;
          var aTFrame = aDoc.textFrames;
          contentString = aTFrame[0].contents;
          contentString = contentString.replace ('May-', 'Mai-');
          contentString = contentString.replace ('June-', 'Juin-');
          // contentString … and so on
          aTFrame[0].contents = contentString;
          redraw();
          

           

           

          Have fun

           

          • 2. Re: Find and replace month names
            virender_CTS Level 1

            Vielen Dank pixxxel schubser.

            I worte below script as per your suggustion and my requirements. Meanwhile this scipt convert English month to german months. Any possibility I can create a script which ask me for German, French and Italy buttons. So if I click on German button, then German's month coding execute and if i click on French then French's month coding execute and so on. I knew it can be done using dialog (in Indesign I sure) but not sure in Illustrator. Kindly advise.

             

            var myDoc = app.activeDocument;

            for (i = 0; i < myDoc.textFrames.length; i++ )

             

            {

                 var textArt = myDoc.textFrames[i];

                

                 for (j =0; j < textArt.words.length; j++ )

                 {

                  var word = textArt.words[j];

             

                    word.contents = word.contents.replace ("Mar", "Maz");

                    word.contents = word.contents.replace ("May", "Mai");

                    word.contents = word.contents.replace ("Oct", "Okt");

                    word.contents = word.contents.replace ("Dec", "Dez");

                   

                  }

                }

             

             

            //alert("Done");

            • 3. Re: Find and replace month names
              pixxxel schubser Level 5

              Gern geschehen.

               

               

              You mean something like this?

               

              // ReplaceMonthNames.jsx
              // ersetzt im obersten Textframe englische Monatsnamen (z.B. 'May-') durch die deutsche oder italienische Variante
              // http://forums.adobe.com/thread/1289008?tstart=0
              // regards pixxxelschubser
              
              var aDoc = app.activeDocument;
              var MonthReplace, end = null;
              var Engl = new Array ('Jan-', 'Feb-', 'Mar-', 'Apr-', 'May-', 'June-', 'July-', 'Aug-', 'Sept-', 'Oct-', 'Nov-', 'Dec-');
              var German = new Array ('Jan. ', 'Febr. ', 'März ', 'Apr. ', 'Mai ', 'Juni ', 'Juli ', 'Aug. ', 'Sept. ', 'Okt. ', 'Nov. ', 'Dez.');
              var Italy = new Array ('Gen. ', 'Feb. ', 'Mar. ', 'Apr. ', 'Mag. ', 'Giu. ', 'Lug. ', 'Ago. ', 'Set. ', 'Ott. ', 'Nov. ', 'Dic.');
              
              var win = new Window("dialog");
              win.alignChildren = "left";
              win.German = win.add("radiobutton", undefined, "deutsch");
              win.Italy = win.add("radiobutton", undefined, "italienisch");
              win.cancelBtn = win.add("button", undefined, "Abbruch");
              win.quitBtn = win.add("button", undefined, "Ok");
              win.defaultElement = win.quitBtn;
              win.cancelElement = win.cancelBtn;
              
              win.German.value = true;
              
              win.quitBtn.onClick = function() {
                  end = 1;
                  win.close();
                  }
              win.show();
              
              if(end == 1) {
              if (win.German.value == true) {
                  MonthReplace = German;
                  } else {
                  MonthReplace = Italy;
                  }
              
              var aTFrame = aDoc.textFrames[0];
              var aCon = aTFrame.contents;
              for (i = 0; i < 12; i++) {
              aCon = aCon.replace( Engl[i], MonthReplace[i]);
              }
              aTFrame.contents = aCon;
              app.redraw();
              }
              
              • 4. Re: Find and replace month names
                virender_CTS Level 1

                Thanks. Yes this is exactly my requirements.

                 

                I will check this at office on Tuesday.

                 

                Vielen Dank und Gruss

                Virender