Google Translation API Macro (v10.0.2)

Hi all, I just got the Google Translate api working on my KM. As usual the most difficult part is to get the google api credentials registered on the Mac's environment. Please see this video Translating speech using cURL - YouTube for the process. I used the authorization via service accounts method. And it worked as per the video. This link is helpful too. Setup  |  Cloud Translation  |  Google Cloud especially the section on " Using the service account key file in your environment."

After that, I used the following macro to call for google translate. I have also another macro that sets the target language (%Variable%lang%). By default, the target language is english.

I use a JSON parser called JQ to process the JSON results. But you don't have to use that. A simple search and extract function is sufficient to extract the translated results.

To use the shell script, I have to include source ~/.bash_profile to include the environmental variables that referenced the google api credentials.

Google Translation API Macro (v10.0.2)

Google Translation API.kmmacros (4.8 KB)

2 Likes

That opens up a lot of opportunities. It got me wondering if macOS supports the iOS Translate app with some kind of API. And I think it does:

I should be adding to my wish list of future KM upgrades that KM obtain new actions that interface with this API.

You got me excited, so I tried to see if I could do it myself within MacOS. And I have a rudimentary method working. Firstly, you have to turn on the setting called "Enable Mouse Keys." Then here's some sample code that will translate the "copied text" into another language. It's very rudimentary, but it shows it can be done.