• Become a Power user Intro to AutoHotkey Intermediate AutoHotkey Intermediate Objects GUIs are Easy w/AutoHotkey Painlessly switch from V1 to V2

Google Translate API for Texting

Google Translate APIUse the Google Translate API for texting.  My example has it translating English to Spanish and Spanish to English but this is easily tweaked!

How to use the Google API to translate texts
How to use the Google API to translate texts

The video demonstrates how to use Google Translate API with API keys, keyboard shortcuts, query string builders, and JSON parsing to translate text between English and Spanish for distraction-free programming.

  • 00:00 Use Google Translate API with your own API key, implement “single instance force” and hide system tray icon for distraction-free programming.
    • The speaker demonstrates how to use Google Translate API and provides the code for it, emphasizing the need for obtaining one’s own API key.
    • Use the “single instance force” to ensure a program only runs once and hide the system tray icon to avoid distractions.
  • 01:24 Use keyboard shortcuts to translate text between English and Spanish with the help of clipboard and API call function.
    • The speaker explains how to use keyboard shortcuts to translate selected text from English to Spanish and vice versa, utilizing the clipboard and an API call function.
  • 02:31 Use a query string builder to pass key value pairs for an API, including language codes and API keys, with alphabetical order and ternary for question mark or ampersand.
    • The speaker explains how to use a query string builder to pass key value pairs for an API, including language codes and API keys.
    • The code sends a request with key, API key, source, and q values in alphabetical order, using a ternary to determine whether to use a question mark or ampersand, and key-value pairs for the clipboard.
  • 04:26 Learn how to extract text from a JSON response by building a query string, making an API call, and parsing the JSON.
    • The lecture discusses building a query string, making an API call using Win HTTP request, and parsing the JSON response to extract the desired text.
  • 05:45 Learn how to translate English to Spanish using an API call and sleep function to avoid clipboard issues.
    • The lecture explains how to translate text from English to Spanish using an API call and a sleep function to avoid issues with the clipboard.
  • 07:07 Using a text program and app, the speaker swaps out text and translates replies with hot keys and object manipulation.
    • The speaker explains how they use a text program and an app on their phone to swap out text and translate replies, utilizing hot keys and object manipulation.
  • 08:25 A script to connect to APIs is now available for download.
    • The speaker created a simple script to connect to APIs and will make it available for download.
  • 08:59 Create a GUI to translate text between English and Spanish and take the intermediate autohotkey course for advanced techniques.
    • Create a GUI with two side-by-side interfaces in English and Spanish to easily translate text.
    • Take the intermediate autohotkey course to learn advanced techniques and organize your learning in a systematic way.


hey it’s your glance meowmeter and i’m gonna demonstrate here in a minute and give you the code for using google translate using their api so the google api for translating is awesome i saw a free version of the google translate thing on the website which you can use browser calls for doing the stuff and so it’d be free but sometimes there’s some delays and that and using their api it’s also unless you hit a threshold it’s still free you do have to get your own key though so here i’m going to
cover that but let’s jump into this code here in a second meanwhile if you could like this video i’d really appreciate it help me out and let’s get going all right so in the translate i have a several different functions that i’m using here and this is because i’ve been helping a local business that and they don’t really speak english well so i’ve been using google translate to get what they write me they text me and i’ll display it in english they’re sending it in spanish then i convert it use i’ll reply back
and then send them back spanish sofor me ctrl shift t so i just up here i’m reading in my authorization my api key which i have hidden so i can share this whole script it doesn’t matter again you’ll have to get your own api key and i’ll give you the urls here which you can go look up on how to get one and apply for one or you know you register onei have i don’t because i’m having this thing running all the time i have the system tray icon hiddenthere’s a single since force which
you should know what that is forces it to only run once and if i don’t actually remember if i still have it looks like sometimes i do i’m restoring the clipboard because i’m utilizing the clipboards because i was lazy and didn’t find a better way to do this i’m borrowing my clipboard and then i like your time shoving the old content back into the clipboard so it doesn’t remove what was in my clipboard now this good selected text again because i’m calling it twice the ctrl shift t is going to translate so for me the t is
for translating from english to spanish and then ctrl shift b is just a back it’s like a reverse translate for me so for spanish to english now we’re going to keep walking through this linearly so get selected text so that means it jumps down to here it says oh okay let’s let’s store the clipboard all into clipboard backup let’s blanket we’re going to send control c so send a copy and then wait for up to one second for something to be inside the clipboard right for it to detect if it doesn’t detect it it’s going to
return and just stop the process because if it didn’t find selected text then i don’t want to keep moving forward so when it finishes that it’s going to come back and now has the content that was selected so this would be like this this would be selected and then it does the api call function which actually has the call to another function inside of it so let me explain this query string builder which you can see down here right i’m passing it key value pairs hopefully you’re familiar with objects
if notit’s in i think my intermediate AutoHotkey course or i have othe-Automator but here we can see source is es now es is the the short code for like spanish rightand the target which is sources what language is it coming in in what the target is what i want to translate it into and that’s en for english right for the u.
s english and you can go look these up there’s a lookup table somewhere if you just start looking for two-letter code language abbreviations you’ll find this really long long long list and then i pass the key the word key with my api key and then i’m passing q for the query with the clipboard right so it’s passing each of those things that jumps down into my query string builder because apis they they want to send key value pairs and if the very first one needs to be like your in this case it might be actually i think it’ll be alphabetical so
um [Music] so i would say because that’s q and this is oh sorry so the very first one would be the key because that’s the lowest letter if it does alphabetize it so it would send key and then because it’s the first time through it would put a question mark and then it would append mymy api key and then it will send looks like source and then an ampersand and then es and that’s because in here i have a ternary which is a fancy way to do some logic if it’s the first time through use the question mark after that use the
ampersand right so that’s what this solves and here we have the a and the b this is the key value pairs so it’s going to put key equals this and then q equals clipboard right that’s what’s going to happen down in here it’s going to build my query string as a string and return that up to here and then do the api call now the api call is going to jump down into this function passing the query string now because the endpoint doesn’t change i just hard coded that also i heard could it’s a get request if you’re new to api
keys we have a great webinar and i have a lot of videos on apis api calls web service api calls to be more specificin here though really all i needed to change was this query string right so i figured i’m going to hard code these and not have them change we’re using the win http request so this is theit’s basically a way for you to go connect to a server and submit a query and then you capture what gets returned so here is where we submit the query at this endpoint this is called your endpoint and we send
it we get the response back now this response text that’s going to be the text value and it’s actually if i remember right oh yeah it’s a json and i take the json shove it into an AutoHotkey object and then i know just from studying the json this is what i want right i only want this thing and that’ll be the text that gets translated so let’s do an example here it’s i think it’s always running i’m going to launch it just to make sure and let’s say actually you know what if let’s add
no not there let’s do it up here and we might even have it up at the top here nope so i’m gonna comment it out otherwise it gets confusing so if i said good morning and now i’m going to highlight this and hit control shift t so if it went did that api call returned that back buenos dias good morning rightand so what i what i should have finished here was it does the api call returns it back gets the text and then i have a sleep just so it waits just for a secondsends control v i shouldn’t say
second because it’s two tenths of a secondsends control v and you want to make sure you really are good about this before you restore your clipboard value make sure this has at least i think it’s most people say like 50 but who cares right i put it at 300 because if it tries to restore your clipboard too fast it ends upreplacing it with the original clipboard or i’m sorry with it does it so fast sorry what happens is it sends the control v after you restore the clipboard so you send the original it’s really confusing
so just make sure you haveasleep after you send the paste otherwise it’ll say hey okay paste and before it can actually paste it restores your clipboard to the original and it’s really confusing so that’s the translating from english to spanish however once i get the spanish version now this also i am literally swapping out you saw it change the text here why is that well because in my text program and i’m in this case i’m using the the app herethe phone your phone with a terrible nameon windows
and so i can just this way i can type here and hit ctrl shift t and it’s going to swap it out in this for me right which is how i want to use thisif i get replies the thing is if i want to translate his reply that’s what i sent him still in spanish it doesn’t matter but i couldn’t swap it out because this is not an edit field so i have it throw up a tool tip so if i hit ctrl shift b this is highlighted then it then i’ll stop by the afternoon maybe around three so that just did that translation for me
um and we could take the buenos dias and do it back here ctrl shift b good morning now it shows you that right this is almost exact the front end’s all exactly the same i have a HotString builder except for here i’m saying the source is spanish and translated in the english right this is where objects are amazing once you get used to them this is a storage vehicle but here i say okay let’s let’s start a tool tip with what’s returned
um give it a little bit of time to sleep restore the clipboard and wait a little bit longer for three seconds just so i can read it i can adjust this or i could throw this in a message box if it gets to where i i want to have it where i can decide when to tell it okay but it’s that simple of a script so i’m going to make this available i’ll put the download somewhere over my head or something i hope it helps apis are just amazing tools it’s so cool that without a hockey we can connect to apis and play with them and i hope this was
really helpful remember please like that and add some comments here if you’re confused on something or if you found something not helpful or if you would change what i would probably do to make this more generic is have a gui isaias isn’t available at the moment unfortunately but i would have two side-by-side gooeys one in english one in spanish and just have it where i would go in and hit a button on the bottom of each one type in one field hit a button have it translate for me maybe dump it into the other one so i
can see thatbut this was just a simple one that i’m using it so much in the texting i wanted something closer to have it tied to the texting where it’s super easy to use so hope that helps cheers hey thank you for watching that video and if you just enjoyed that you probably aren’t at the beginning level and i highly recommend you work through the intermediate AutoHotkey course you can see the url over my head here which will give you a coupon discount and you learn a lot of you know more advanced things of working with
controls loops and functions and objects and there’s a lot of great stuff with file paths and and then what you can do AutoHotkey is an amazing tool the having the course will help you have a direction of where to go in a flow and a work through because otherwise we kind of learn a lot ofHotkey here and there and it gets to be a big ball of messso art having the course helps you make sure you work through it in a systematic way i hope you enjoy it cheers

Comments are closed.