The Unbearable Frustration of Figuring Out APIs

https://news.ycombinator.com/rss Hits: 3
Summary

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 Thankfully, Swift was already set up on my machine with an LSP and a formatter and the works. I had even followed the basic tutorial and the file is on my machine already, A small edit and I can be on my way. For reference, this is the code at the end of the tutorial: import ArgumentParser import Figlet @main struct FigletTool: ParsableCommand { @Option(help: "Specify the input") public var input: String public func run() throws { Figlet.say(self.input) } } After so long in Rust and Zig lands, the most jarring thing about Swift so far is that import creates...

First seen: 2026-01-14 17:10

Last seen: 2026-01-14 19:11