Better smart quotation marks while typing (like in Word) for files and languages with missing settings

Hi,

I’ve been fiddling around quite some time now in order to get it working without triggering errors in Trados Studio (beginning and end of line and first or last line, aso.) but now this gives custom quotation marks just like in Word. They are placed according to their relative position to the text (opening vs. closing) and not depending on if you already typed a quotation mark or not (existing script from Jesus Prieto (if I remember correctly)). It even works if you place the caret anywhere in your segment and type a ".

#IfWinActive, Trados Studio
"::
OldClipboard := % Clipboard
Clipboard := ""
Caretx := A_CaretX
Carety := A_Carety
MouseGetPos, Mousex, Mousey
Send ^a
Send ^c
ClipWait 1
if (ErrorLevel)
{
	send „ ;open
}
else
{
	MouseMove, % Caretx, % Carety
	Click, Left
	MouseMove, % Mousex, % Mousey
	Send, {shift down}{left}
	Send, {shift up}
	Send, ^c
	Send, {right}
	ClipWait, 2
	mycheck := Clipboard
	if (RegexMatch(mycheck,"[^\s]"))
	{
		send “ ;close
	}
	else
	{
		send „ ;open
	}
Clipboard := % OldClipboard
}
return
#IfWinActive

Notes:

I set it with code to only work in Trados Studio, if you want to use it anywhere just remove the first and the last line of the above code.

It is triggered if " (straight quotation marks (Shift +2 on German keyboard)) is typed, if you want another character as trigger, just replace the " in line ":: with the character you want.

This one uses German curly quotation marks but you can just replace the quotation marks with the ones you would like to by replacing the characters before the seceral ;open or ;close parts respectively. It could also be used for Spanish exclamation and question marks as they follow the same behaviour.

You might see your mouse cursor jump around, that’s intended, so no need to worry about it.

Best regards,

Pascal



Edit: added code to keep mouse at initial position and to preserve clipboard text
[edited by: Pascal Zotto at 4:47 PM (GMT 0) on 21 Nov 2022]
emoji
Parents
  • Good! I like the idea of checking the previous character!

    I only wanted to have a quick test and I ended up trying new things. Grinning

    I'd add checking also for opening brackets ((): if (RegexMatch(mycheck,"[^\s\(]"))

    Also if I remove lines 8 and 9, I get an opening quotation when the segment is empty (I guess that was the purpose).

    Does the script following script work for you (I removed a few lines)?

    #IfWinActive, Trados Studio
    "::
    OldClipboard := % Clipboard
    Clipboard := ""
    
    Send, {shift down}{left}
    Send, {shift up}
    Send, ^c
    ClipWait, 2
    Send, {right}
    mycheck := Clipboard
    if (RegexMatch(mycheck,"[^\s\(]"))
    {
        send “ ;close
    }
    else
    {
        send „ ;open
        
    Clipboard := % OldClipboard
    }
    return
    #IfWinActive

    emoji
  • Hi ,

    the lines you removed are unfortunately necessary even if they seem superfluous as else we get are erroneous placements especially at the end of the segments. So, no, it does not correctly work in all cases without these lines.

    I had to add those 2 lines in order to avoid Trados error messages especially within the very first segment.

    Yes, you’re right, I completely forgot about that usecase. But then we need to add the other brackets too. ;)

    #IfWinActive, Trados Studio
    "::
    OldClipboard := % Clipboard
    Clipboard := ""
    Caretx := A_CaretX
    Carety := A_Carety
    MouseGetPos, Mousex, Mousey
    Send ^a
    Send ^c
    ClipWait 1
    if (ErrorLevel)
    {
    	send „ ;open
    }
    else
    {
    	MouseMove, % Caretx, % Carety
    	Click, Left
    	MouseMove, % Mousex, % Mousey
    	Send, {shift down}{left}
    	Send, {shift up}
    	Send, ^c
    	Send, {right}
    	ClipWait, 2
    	mycheck := Clipboard
    	if (RegexMatch(mycheck,"[^\s\[\{\(]"))
    	{
    		send “ ;close
    	}
    	else
    	{
    		send „ ;open
    	}
    Clipboard := % OldClipboard
    }
    return
    #IfWinActive

    Best regards,

    Pascal

    emoji
Reply
  • Hi ,

    the lines you removed are unfortunately necessary even if they seem superfluous as else we get are erroneous placements especially at the end of the segments. So, no, it does not correctly work in all cases without these lines.

    I had to add those 2 lines in order to avoid Trados error messages especially within the very first segment.

    Yes, you’re right, I completely forgot about that usecase. But then we need to add the other brackets too. ;)

    #IfWinActive, Trados Studio
    "::
    OldClipboard := % Clipboard
    Clipboard := ""
    Caretx := A_CaretX
    Carety := A_Carety
    MouseGetPos, Mousex, Mousey
    Send ^a
    Send ^c
    ClipWait 1
    if (ErrorLevel)
    {
    	send „ ;open
    }
    else
    {
    	MouseMove, % Caretx, % Carety
    	Click, Left
    	MouseMove, % Mousex, % Mousey
    	Send, {shift down}{left}
    	Send, {shift up}
    	Send, ^c
    	Send, {right}
    	ClipWait, 2
    	mycheck := Clipboard
    	if (RegexMatch(mycheck,"[^\s\[\{\(]"))
    	{
    		send “ ;close
    	}
    	else
    	{
    		send „ ;open
    	}
    Clipboard := % OldClipboard
    }
    return
    #IfWinActive

    Best regards,

    Pascal

    emoji
Children
No Data