Skip to main content
Participant
July 10, 2014
Answered

How to change the order of two sets of words

  • July 10, 2014
  • 2 replies
  • 296 views

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!!

This topic has been closed for replies.
Correct answer Johnwhite

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

2 replies

Inspiring
July 10, 2014

as easy as a pie

Inspiring
July 10, 2014

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

maloyuAuthor
Participant
July 10, 2014

Thanks, Johnwhite, I got your idea.


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.

maloyuAuthor
Participant
July 10, 2014

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