**The Unbearable Frustration of Figuring Out APIs**

As a developer, there's nothing quite like the thrill of tackling a new project. But sometimes, even with the best intentions and a healthy dose of determination, things can get... interesting.

In my latest endeavor, I decided to create a simple command-line tool that could translate text on demand. It seemed like a straightforward task – after all, who doesn't love a good challenge? And what better way to fill the void left by unemployment than with a project that required me to learn Chinese?

With the help of a local language institute and a trusty dictionary app, I got started on my journey. But as soon as I opened up TextEdit to translate some text, I hit my first snag: not every app supports right-clicking and selecting "Translate." Time to get creative.

I decided to write a small command-line tool that would take user input, send it off to the translation API of my choice, and then spit out the translated result. Easy peasy, right? I mean, who needs experience with APIs when you've got Google at your fingertips?

As it turns out, every API I looked at wanted an API token, a rate limit, and – in some cases – even a credit card number. Who knew that something as simple as text translation could be so... complicated?

Suddenly, my trusty Mac's built-in Translate feature didn't seem like such a bad idea after all. Maybe I could just hook into that? After all, it had to be easier than dealing with APIs and tokens and whatnot.

But nope. As soon as I tried to dig in, I realized that the Translate feature was using the Dictionary service instead of the Translation service. Who knew they were different? Okay, okay – let's do this thing in Swift instead. It can't be that hard, right?

I'd been meaning to learn Swift for a while now, and what better time than the present? I fired up Xcode, followed the basic tutorial, and before long, I had my very own Swift project set up and running.

But of course, it wasn't quite that simple. As soon as I tried to use the Translation service, I hit another snag: Swift's async functions don't play nice with Zig (a language I'd been using for other projects). Time to write a Swift shim... or maybe just do this thing in Swift after all?

After what felt like an eternity of trial and error, I finally had my code set up. But as soon as I ran it, I hit another snag: the API user should check language availability before translating. Yeah, because that's not a huge pain to implement.

But don't worry – I'm not here to complain (much). With the help of some online tutorials and WWDC videos, I finally got my code working. And it was... a thing of beauty.

Want to try it out for yourself? Just run `swift run -q MyCLI 你好` in your terminal, and see what happens! (Note: this assumes you have the Translation API set up correctly on your Mac.)

Or, if you're feeling adventurous, you can even install the models through System Settings. Who knows – it might just work this time.

**The Full Final Code**

```swift import NaturalLanguage

func run() async { let recognizer = NLLanguageRecognizer() let language = await recognizer.recognizeLanguage(input: "你好") print("Detected language: \(language)") }

@main struct MyCLI: ParsableCommand { @Argument(help: "Input text to translate") var input: String func run() async throws { let session = TranslationSession() let result = try await session.translate(input) print(result.translation) } } ```

So there you have it – my epic journey into the world of APIs, Swift, and (of course) Chinese translation. May your own experiences be less... eventful.

**Bonus Tip:** If you're having trouble with language detection, don't forget to check the user's language preferences in System Settings!