Tech News
← Back to articles

The Unbearable Frustration of Figuring Out APIs

read original related products more articles

In the ongoing effort for activities that fill the void made by unemployment, I have recently started to learn Chinese. Got into a Chinese language institute and everything. And because not every app supports right-clicking some text and selecting the "Translate" menu option, I found mysekf launching TextEdit just to do that. So, I figured, maybe I can do a small command line tool where I'd write something like:

translate 你好

And the terminal would hppily tell me it means "Hello". Should be easy. A hungry ghost trapped in a jar can probably figure it out in one shot.

First I figured I'd look for some translation API. Almost everything I looked at seemed to want an API token and there is a rate limit (not that I'd hit it), and maybe a credit card number. Then I remembered that macOS has that Translate right click action, surely I can just hook into that.

Note that this article, unlike what I do usually, is written after the fact.

First Steps

Zig

I have been using Zig for different project this year. So I got the Ghost to write the thing for me, and it even gave me the correct flags to pass to the compiler! But then when I tried it, I realized it used the Dictionary service instead of the Translation service. When I asked it for that instead, it was like yeah you cannot call Swift async functions from Zig, you need a Swift shim.

So let's do the thing in Swift instead. I have been meaning to learn Swift anyway.

MyCLI

... continue reading