Pages in topic:   [1 2] >
Is there an easy way to reverse the order of words in the target text?
Thread poster: Brent Sørensen

Brent Sørensen  Identity Verified
Germany
Local time: 01:22
Member (2016)
German to English
+ ...
Mar 26, 2020

I know this is a long shot but here goes:

Say I have the following text in my target:
...by the responsible person
I would like to change it to:
...by the person responsible

Is there some sort of shortcut/hack that I could use to switch the words without cutting and pasting?


 

Natalie  Identity Verified
Poland
Local time: 01:22
Member (2002)
English to Russian
+ ...

Moderator of this forum
SITE LOCALIZER
But Mar 26, 2020

what about just search and replace?

expressisverbis
 

Brent Sørensen  Identity Verified
Germany
Local time: 01:22
Member (2016)
German to English
+ ...
TOPIC STARTER
I am looking for a way to reduce the number of keystrokes Mar 26, 2020

Thanks for your suggestion. Search and replace would be fine if I had many instances of this in the text.

What I am looking for is something similar to the shortcut for changing the case (i.e. you highlight the text, push a key combination and you toggle through the different cases).
It would be nice if I could just highlight "responsible person" and hit a couple of keys and reverse the order of the words.


 

Samuel Murray  Identity Verified
Netherlands
Local time: 01:22
Member (2006)
English to Afrikaans
+ ...
@Brent Mar 26, 2020

Brent Sørensen wrote:
Say I have the following text in my target:
...by the responsible person
I would like to change it to:
...by the person responsible


You'd have to write an AU3 or AHK script and run it. A few thoughts:

What should happen when more than 2 words are selected? Should "the quick brown fox jumps" change to "jumps fox brown quick the" or to "jumps quick brown fox the"?

What would be more useful to you: being able to select words and then have them reversed, or being able to select just one word and then move the cursor to its new position and paste the word there, but with fewer shortcuts?

Would you be able to select whole words, or would you want the script to make sure that whole words were selected before applying the change? I mean, if the text is "brown fox" and you select "rown fo" and press the shortcut, do you want it to be changed to "fox brown" or "bfo rownx"?

When you select two words, do you also select the space that comes after the second word? Or are you smart enough not to select that extra space?


[Edited at 2020-03-26 21:17 GMT]


Jaime Oriard
 

Anthony Rudd

Local time: 01:22
German to English
+ ...
word reversal Mar 26, 2020

I am not sure what your problem is?
Do you want to automate the reversal of a "pattern" of words? If so, a regex is the answer.
If often do this when German has been translated to English by non-native speakers, and a noun is placed before the term to which it applies, such as
class "Big Job" -> "Big Job" class


 

Stepan Konev  Identity Verified
Russian Federation
Local time: 03:22
English to Russian
regex Mar 26, 2020

Anthony Rudd wrote:
a regex is the answer.

Could you please write that regex here? Thank you.


 

Samuel Murray  Identity Verified
Netherlands
Local time: 01:22
Member (2006)
English to Afrikaans
+ ...
Here's an AutoIt script for you, in the mean time Mar 26, 2020

Brent Sørensen wrote:
Say I have the following text in my target:
...by the responsible person
I would like to change it to:
...by the person responsible


Okay, here's a simple AutoIt script that does it:
http://www.leuce.com/autoit/transpose_words.zip

So, you have to install AutoIt to make this work. Run the script, and then your shortcut keys are Shift + Ctrl + comma and Shift + Ctrl + fullstop (or customise it in the script). Select words in Trados, and press the shortcut. You can undo by pressing Ctrl + Z once or twice.

If you accidentally select a space at the end, the script compensates for it. The script does not compensate if you accidentally select something else, or if you accidentally do not select an entire word.

Shift + Ctrl + , = reverse words

Examples:
one two = two one
one two three = three two one
one two three four = four three two one

Shift + Ctrl + . = switch first and last words

Examples:
one two = two one
one two three = three two one
one two three four = four two three one

To exit the script, right-click it on the system tray.

However, I suspect you're not going to be using this function as often as you might have originally thought.


 

Stepan Konev  Identity Verified
Russian Federation
Local time: 03:22
English to Russian
AHK script Mar 26, 2020

If you are lazy enough (as lazy as me), you just must install AHK freeware from https://www.autohotkey.com
Once done, create a txt document anywhere on your hard drive (create a dedicated folder for your future AHK scripts), paste the following script, then save as ahk by typing 'ahk' after the file extension dot. For example, save as SwapWords.ahk
(The dashed line here is just for visual clarity.
... See more
If you are lazy enough (as lazy as me), you just must install AHK freeware from https://www.autohotkey.com
Once done, create a txt document anywhere on your hard drive (create a dedicated folder for your future AHK scripts), paste the following script, then save as ahk by typing 'ahk' after the file extension dot. For example, save as SwapWords.ahk
(The dashed line here is just for visual clarity. You don't need it in your ahk script)
---------------------------------------------------------------
F1::Swap("Left")
F2::Swap("Right")

Swap(dir:="Left")
{
clipSave := ClipboardAll
Clipboard := ""
Send, % "{Shift down}{Ctrl down}{" dir " 2}{Shift up}c{Ctrl up}"
Clipboard := RegExReplace(Clipboard, "(\S+) +(\S+)", "$2 $1")
Send, {Ctrl down}v{Ctrl up}
Clipboard := clipSave
}
---------------------------------------------------------------
If you have done it right, you will see an ahk file with an H-icon. Click it twice to run the script—it will appear in your system tray.
From now, you can use F1 or F2 buttons to swap two words to the left of the cursor (F1) or two words to the right of the cursor (F2).
Collapse


 

Stepan Konev  Identity Verified
Russian Federation
Local time: 03:22
English to Russian
Wow! Simultaneous solutions Mar 26, 2020

A better choice would be the regex mentioned by Anthony Rudd. I hope he will share it here.
However, now you have at least two scripts for that


 

Anthony Rudd

Local time: 01:22
German to English
+ ...
Regex Mar 27, 2020

But of course.

The "simple" regex
\bclass\s"?([A-Z][a-z]*(\s[A-Z][a-z]*)*)"?
Replace string: $1 class

converts strings such as
The class "Big Job" object
The class Big Job object
to
The "Big Job" class object
The Big Job class object

The " is optional. The word "class" may be followed by one or more uppercased words.
The "simple" regex assumes each word is separated with a single whitespace (\s)


 

Stepan Konev  Identity Verified
Russian Federation
Local time: 03:22
English to Russian
Thank you Anthony for the regex, but... Mar 28, 2020

Anthony Rudd wrote:
The "simple" regex
\bclass\s"?([A-Z][a-z]*(\s[A-Z][a-z]*)*)"?


As far as I understand this is a replacement method for constants only, i.e. you can only replace one and the same word 'class' with different letters (class A, ... class Z), right? But how you do the same for any two words? With AHK script, you don't even need to select the words. Just place cursor before or after the words and press F1 or F2 to swap them. Hardly you can do this trick with regex.


 

Anthony Rudd

Local time: 01:22
German to English
+ ...
Regex vs. AHK Mar 28, 2020

True. The 2 methods are not strictly comparable. Obviously "class" can be replaced with a list of words and regexes allow rules to be specified.

 

Andrzej Mierzejewski  Identity Verified
Poland
Local time: 01:22
Polish to English
+ ...
Find and replace Mar 30, 2020

I second Natalie's post: 'Find and replace' is the easiest method. This is just the smallest number of keystrokes possible. You only must modify the order of the required two or three words. No need to compose any macro or download any software.

HTH


 

Samuel Murray  Identity Verified
Netherlands
Local time: 01:22
Member (2006)
English to Afrikaans
+ ...
Which... Mar 30, 2020

I think there is a misunderstanding of what is required.

Here is a nursery rhyme with four segments, three of which require a reversal:

1. Tom, Tom, the son piper's, (change "son piper's" to "piper's son")
2. Stole a pig, and did away run; (change "did away" to "away did")
3. The pig was eat and Tom was beat,
4. And Tom crying went down the street. (change "Tom crying" to "crying Tom")

Manual replacement method: Click and select " piper's
... See more
I think there is a misunderstanding of what is required.

Here is a nursery rhyme with four segments, three of which require a reversal:

1. Tom, Tom, the son piper's, (change "son piper's" to "piper's son")
2. Stole a pig, and did away run; (change "did away" to "away did")
3. The pig was eat and Tom was beat,
4. And Tom crying went down the street. (change "Tom crying" to "crying Tom")

Manual replacement method: Click and select " piper's", press Ctrl+X, click next to "the", press Ctrl+V. Or use the arrow keys to select text.

Find/replace method: Press Ctrl+H; type or paste "son piper's" in the Find field, press TAB, then type or paste "piper's son" in the Replace field; make sure the cursor is before the first word (e.g. press HOME), and then press Alt+N (for "Find") and then Alt+R (for "Replace") and then Alt+C (to close the dialog); and then (because Trados doesn't have the ability to replace and remain), press Ctrl+Z to move the cursor back to the segment, and press Ctrl+Y to redo the replacement, and finally press the right arrow to deselect.

Regex method: Press Ctrl+H; type or type and paste "(son)( )(piper's)" in the Find field, press TAB, then type "$3 $1" in the Replace field; make sure the cursor is not after the first word (e.g. press HOME), and then press Alt+N (for "Find") and then Alt+R (for "Replace"); then press Escape (to cancel the one dialog) and then Alt+C (to close the other dialog); Using regex replace puts the cursor at the start of the segment, so if that is what you want, good, but otherwise, press Ctrl+Z to undo the replacement, and press Ctrl+Y to redo the replacement, and finally press the right arrow to deselect.

AHK script: Click or use arrow keys to move cursor to directly after "piper's", and then press F1 (or your chosen shortcut).

AU3 script: Use the mouse or arrow keys to select "son piper's", and press Shift+Ctrl+' (or your chosen shortcut)



[Edited at 2020-03-30 17:57 GMT]
Collapse


 

Stepan Konev  Identity Verified
Russian Federation
Local time: 03:22
English to Russian
Did you read the second post by Brent Sørensen ? Mar 30, 2020

Andrzej Mierzejewski wrote:
'Find and replace' is the easiest method.

You can only use this method when "the required two or three words" are always the same. This is not the case here.

[Edited at 2020-03-30 16:44 GMT]


 
Pages in topic:   [1 2] >


To report site rules violations or get help, contact a site moderator:


You can also contact site staff by submitting a support request »

Is there an easy way to reverse the order of words in the target text?

Advanced search







SDL Trados Business Manager Lite
Create customer quotes and invoices from within SDL Trados Studio

SDL Trados Business Manager Lite helps to simplify and speed up some of the daily tasks, such as invoicing and reporting, associated with running your freelance translation business.

More info »
CafeTran Espresso
You've never met a CAT tool this clever!

Translate faster & easier, using a sophisticated CAT tool built by a translator / developer. Accept jobs from clients who use SDL Trados, MemoQ, Wordfast & major CAT tools. Download and start using CafeTran Espresso -- for free

More info »



Forums
  • All of ProZ.com
  • Termsøk
  • Jobber
  • Forumer
  • Multiple search