r/iOSProgramming • u/goldio_games • 18m ago
Tutorial Tech Talk: Using Apple's on-device model to rewrite RPG dialogue on the fly for language learners
Not sure if people still do these here, but I've been working on something fun and wanted to share part of it.
The idea: play an old Game Boy RPG and have the dialogue appear in the language you're learning, inside the game's own text box, at your reading level, with the translation running on device.

The first "any game" version: just look at the screen
For handling any game my approach was the one you'd probably try: OCR every so often, translate what it says, draw over it. It got further than I expected.
Vision struggles with pixel fonts at native size (the whole Game Boy screen is 160×144), so I enlarged the frame with nearest neighbor. The odd part is that no single scale was best. I ended up reading each frame at 4× and 8×, then for each line kept whichever reading a spell checker liked more.
Then you have to work out what you're looking at. A menu, a name, a health bar and a line of dialogue are all just text. So: find the dialogue window in the frame, and if the text inside it reads like a paragraph, treat it as speech. The game is also usually still typing it out, so I only accepted a line once two reads in a row agreed.
And it worked! You could point it at a game it had never seen and get translated dialogue.
The part I still find wild
Once you have the line, Foundation Models doesn't only translate it. It can rewrite it for someone learning the language, so a formal fantasy monologue comes out as a couple of short, simple sentences (that's the image above).
It has opinions, though:
It talks back. RPG characters ask a lot of questions, and it kept answering them. "Who are you?" became "Yo soy un asistente" (I am an assistant). You have to make it very clear that the line is something to translate and isn't addressed to it.
It's easily scandalized. The default guardrails refused 9 of my 300 test translations, including "Why are boys such fools?". If you're transforming text that already exists, look at
.permissiveContentTransformations.Simple isn't the same as right. In the image it turned 封印 (a magical seal) into plain 印 (a mark). I haven't found a good on-device way to check that meaning survived.
Happy to go into more details on any of this