Replace English quotes with French quotes
-
- Posts: 5
- Joined: 19 Sep 2021, 05:30
Replace English quotes with French quotes
Hi, I need a hotkey script that would allow me to select a phrase surrounded by single straight quotation marks and replace it with the same phrase surrounded by French quotation marks with non-breaking spaces after the opening quotation mark and before the closing quotation mark so that
This is a 'test'
would be replaced with
This is a « test »
Can anyone help me out?
Thank you in advance.
This is a 'test'
would be replaced with
This is a « test »
Can anyone help me out?
Thank you in advance.
Last edited by gregster on 19 Sep 2021, 14:57, edited 1 time in total.
Reason: Topic moved from "AHK v2 Help".
Reason: Topic moved from "AHK v2 Help".
Re: Replace English quotes with French quotes
Assuming you aren't really using v2 of AHK but posted in the v2 section by mistake (because most first-time posters aren't really using v2 even if they post here), I'll provide code for AHK v1 (the latest official release). Run the following script, highlight the text of interest, and press Ctrl+' to replace the quotes:
Note that it would run into trouble with cases like Here's a 'test'. It could be make to handle such cases, but even then it would not be able to correctly address cases like this: Pumpkin pie is 'the members' favorite'. I take it you wouldn't be mixing apostrophes and single quotes like that, however.
If you really are using v2, it would be a good task for you to translate it. If you run into trouble, I can help you translate it.
Code: Select all
^'::
ClipSave := ClipboardAll
Clipboard := ""
Send, ^c
ClipWait, 1
if ErrorLevel
return
Clipboard := RegExReplace(Clipboard, "'(.*?)'", "«" Chr(0x00A0) "$1" Chr(0x00A0) "»")
Send, ^v
Sleep, 500
Clipboard := ClipSave
return
Note that it would run into trouble with cases like Here's a 'test'. It could be make to handle such cases, but even then it would not be able to correctly address cases like this: Pumpkin pie is 'the members' favorite'. I take it you wouldn't be mixing apostrophes and single quotes like that, however.
If you really are using v2, it would be a good task for you to translate it. If you run into trouble, I can help you translate it.
-
- Posts: 5
- Joined: 19 Sep 2021, 05:30
Re: Replace English quotes with French quotes
Thank you so much for your help and sorry for using the wrong forum. I wasn't sure where to post. Anyway, the hotkey works like a charm when I use the English keyboard. The only problem is that I usually use the French keyboard so it doesn't work with the single apostrophe in the hotkey. I tried replacing it with another letter in the hotkey but it didn't work. Can you help?
Re: Replace English quotes with French quotes
What key did you change it to that didn’t work? Please show exactly what you changed the first line to and tell me what keys you pressed on your keyboard.
-
- Posts: 5
- Joined: 19 Sep 2021, 05:30
Re: Replace English quotes with French quotes
I tried replacing the first line ^':: with ^q:: because the letter q would be the same on both the English and French keyboards. However, it didn't work and nothing happens after I select the phrase and press on Ctrl-q
Re: Replace English quotes with French quotes
Are you certain you saved the changes to the script and closed other instances before running the new one? And the copied text definitely has straight single quotes as in This is a 'test', not This is a ‘test’? Does the French keyboard produce the same single quote characters as the English keyboard? Can you post the text you are trying to operate on?
Does the hotkey itself work? What does the following script do?
Does the hotkey itself work? What does the following script do?
Code: Select all
^q::MsgBox, Hello
-
- Posts: 5
- Joined: 19 Sep 2021, 05:30
Re: Replace English quotes with French quotes
Sorry, it does work now in both keyboards. Now if you could just change the script so the hotkey would work with both straight single and double quotes, it would be perfect.
Re: Replace English quotes with French quotes
Code: Select all
^q::
ClipSave := ClipboardAll
Clipboard := ""
Send, ^c
ClipWait, 1
if ErrorLevel
return
Clipboard := RegExReplace(Clipboard, "'(.*?)'", "«" Chr(0x00A0) "$1" Chr(0x00A0) "»")
Clipboard := RegExReplace(Clipboard, """(.*?)""", "«" Chr(0x00A0) "$1" Chr(0x00A0) "»")
Send, ^v
Sleep, 500
Clipboard := ClipSave
return
-
- Posts: 5
- Joined: 19 Sep 2021, 05:30
Re: Replace English quotes with French quotes
Thank you so much. It works like a charm