6 Replies Latest reply on Jul 9, 2014 8:48 PM by maloyu

    How to change the order of two sets of words

    maloyu

      Hi everyone:

       

      I am translating a hundreds page of tables in indesign CS5, and need a coding that could help me to change the order of words in a phrase in all documents.

       

      In the output language (Chinese), the order of words normally changes from the input language, e.g:

       

      original: Construction of word1 word2 word3, Construction of word4 word5

      output: word1 word2 word3 Construction, word4 word5 Construction

       

      So, I kinda have a limited sets of words like "Construction", but thousands of "word", so a GREP coding that could change "A B", "A B C", "A B C D"... to "B A", "B C A", "B C D A" will greatly help me out.

       

      An other example:

       

      Input: Construction of Airport in San Francisco

      Output: San Francisco 机场建设   


      If this helps, I can also use an intermediate word for 机场建设, for example jichangjianshe, then change all then back.


      Much appreciate any enlightenment!!

        • 1. Re: How to change the order of two sets of words
          maloyu Level 1

          A friend just told me to use this string. and it worked out. I hope this could help others too.

           

          Find:

                                        ConstructioninChinese (.+)(.+)

          Replace with:

                                        $1$2 ConstructioninChinese

          • 3. Re: How to change the order of two sets of words
            Johnwhite Level 1

            Hi, try this

             

            app.findGrepPreferences = app.changeGrepPreferences = null;

            app.findGrepPreferences.findWhat = "(Construction) of (word1 word2 word3), (Construction) of (word4 word5)";

            app.changeGrepPreferences.changeTo = "$2 $1, $4 $3";

            app.selection[0].changeGrep();

            app.findGrepPreferences = app.changeGrepPreferences = null;

             

            or

             

            app.findGrepPreferences = app.changeGrepPreferences = null;

            app.findGrepPreferences.findWhat = "(Construction) of (word1 word2 word3), (Construction) of (word4 word5)";

            app.changeGrepPreferences.changeTo = "$2机场建设, $4机场建设";

            app.selection[0].changeGrep();

            app.findGrepPreferences = app.changeGrepPreferences = null;

             

            will that help?

             

            John White

            • 4. Re: How to change the order of two sets of words
              Johnwhite Level 1

              if not

              try this

               

              app.findGrepPreferences = app.changeGrepPreferences = null;

              app.findGrepPreferences.findWhat = "(Construction) of ((\\b\\u\\l+\\b ?){1,3}), (Construction) of ((\\b\\u\\l+\\b ?){1,3})";

              app.changeGrepPreferences.changeTo = "$2 $1, $4 $5";

              app.selection[0].changeGrep();

              app.findGrepPreferences = app.changeGrepPreferences = null;

               

              app.findGrepPreferences = app.changeGrepPreferences = null;

              app.findGrepPreferences.findWhat = "(Construction) of ((\\b\\u\\l+\\b ?){1,3}), (Construction) of ((\\b\\u\\l+\\b ?){1,3})";

              app.changeGrepPreferences.changeTo = "$2机场建设, $4机场建设";

              app.selection[0].changeGrep();

              app.findGrepPreferences = app.changeGrepPreferences = null;

               

              or you can change {1,3} to {1,4} or {1,5} depens on the Airport's name

               

              John White

              • 5. Re: How to change the order of two sets of words
                maloyu Level 1

                Thanks, Johnwhite, I got your idea.

                • 6. Re: How to change the order of two sets of words
                  maloyu Level 1

                  the lines had other restrictions like "Construction of Airport of San Francisco: new towers", or "Recovery of Dock X: quay number 2",

                  so I ended up using several commands of GREP, e.g. FIND    constructioninchinese (.+):     REPLACE WITH     $1 constructioninchinese:

                   

                  And those worked out well. So I guess I will just keep GREPing without script.