IF through Google Translate via command line

Hey there,

I’ve started working out the process for binding existing tools together to let people play automagically translated IF games. I use dumbfrotz which is great for piping input and output to github.com/DavidGriffith/frotz/blob/master/DUMB

I also use trans, a command line tool for linux that uses Google Translate (or bing or whatever) to translate between languages. ostechnix.com/use-google-tr … ine-linux/

Once I have them both in place I can issue a command like this:

# ./dumbfrotz ./Advent.z5 |./trans :fr -b

Which starts outputting the text like this:

[code]Bienvenue dans Adventure!
(Tapez HELP pour obtenir des instructions et des informations.)
.
AVENTURE
The Interactive Original
Par Will Crowther (1976) et Don Woods (1977)
Reconstruit en trois étapes par:
Did you mean: Donald Ekman, David M. Padgett (1993) and Graham Nelson (1994)
Donald Ekman, David M. Baggett (1993) et Graham Nelson (1994)
[In memoriam Stephen Bishop (1820? -1857): GN]

Sortie 9 / Numéro de série 060321 / Informer v6.30 Bibliothèque 6/11 S

À la fin de la route
Vous êtes debout au bout d’une route avant un petit bâtiment en brique. Autour
vous êtes une forêt. Un petit ruisseau sort du bâtiment et descend un ravin.

look
*** PLUS *** At End Of Road Score: 36 Départs: 0
.
get all

At End Of Road Score: 36 Départs: 1
.
Forêt: C’est à peine portable.
Route: C’est à peine portable.
Stream: vous n’avez rien à transporter l’eau.
bien maison: c’est à peine portable[/code].

As you can see, you still have to type the commands in english, but I think this could be worked out if I design a user interface in something that lets me pass French/Spanish/Etc to trans, then the generated english to dumbfrotz, then get the english from dumbfrotz and pass that to trans, spitting back out the French/Spanish/Etc again. And, of course, being computer translated introduces all the problems involved with that.

Perhaps in the final UI I should have “Original English” in one pane and “Translation” in another…

Thoughts? Suggestions?
transfrotz.zip (156 KB)

With this command you can start reading in French and also typing commands in French… of course whether the translation makes any sense to the parser is iffy:

[code]

pipexec [ DFROTZ ./dumbfrotz ./Advent.z5 ] [ TRANS ./trans :fr -b ] [ ETRANS ./trans fr:en -b ] “{DFROTZ:1>TRANS:0}” “{ETRANS:1>DFROTZ:0}”[/code]

It appears that if you type things you mean to be in ENGLISH and untranslated as all caps, then trans spits it out untranslated. That could help if you’re having a particularly hard time getting it to understand a translation-mangled command.

I have actually experimentally played a couple of ASM games in their online library that were automatically translated from Russian since they are played in the browser and Chrome can do translate a webpage. It’s not perfect, and sometimes commands presented creatively in the system can confound it, but this is an interesting possibility.

(ASM is a choice engine, so there isn’t any typing input that needs to be translated. The only opportunity is when the author presents a text-entry field which usually just does a variable substitution.)

This is part of why I’m considering making a dual-pane front end to what I’ve got here. One with the original English and the other with the translation. That way it’s a little easier to muddle through when one can’t make the translated commands work.

Probably made in Gambas. So, this will be pretty-much a Linux-only project. Luckily I have experience making small, specific-use distros of Linux. I could make a “Transfrotz” distro that boots off USB.

This is a pretty neat idea! Of course Google Translate is never perfect but it could go a long way. UI-wise, maybe don’t show both at the same time, but give the option to show the original sentence (on hover for instance). I like the mechanism of caps meaning one language and not caps the other.

I thought frotz had problems printing accents, though, because its output isn’t utf-8. Did you find a way to work around that?

Cheers!

Hmmm… I’m a fan of side-by-side panes, but possibly an on hover at some point. I figure with side-by-side it’s easier to get context, and also easier to code to have something “right now.”

As far as frotz and accents. You see, dumbfrotz is a stripped down version of frotz that spits out plain text without all the UI elements. Dumbfotz is spitting out plain english, the trans script is taking that english and sending it to google translate, then the trans script is spitting out the translated text with accents (not frotz), then when you type back it’s the other way around. Dumbfrotz never sees or prints anything other than english and the trans script sits on top of it via pipes (or when i make a UI via filehandle abstractions), but the non-english language never touches dumbfrotz.

So the “way around” is that it’s the trans script printing accents, not frotz.

Ah, of course! So it works for non-English speaking people who want to play games in English, but not the other way around. (But that’s already very interesting!)
Guess we have to wait for Frotz to support utf-8 for the other way around.

Yeah, that’s the general idea I had. The fan mail at the opening of episode 6 of the “Eaten By A Grue” podcast got me thinking about it.

There’s so much IF in the z-machine format written in English, a whole new world of games could be opened for Spanish/French/Russian/Etc speakers if there was an instant-translate tool available.

I actually tried this out with my Inform 7 game url=http://howtophil.com/IF/ “Getting To Work And Other Bullshit”[/url] and it turns out that Chrome will live-translate games in the quixe interpreter (probably works in parchment as well):
Chrome Transslating Quixe.gif

This is vaguely related, but I have a profanity filter that works on twine games, but it breaks if there is a passage name that is also a link that is a profanity itself (one of the Nanobots games does this, maybe insect hospital), since apparently changing the link name messes it up.

Looks like some Twine games translate well with the above method (the chrome built in translator), but the formatting can get a little wacky.

I really want to see this type of thing with ‘plugins’ on top of RemGlk. Despite decades of operating system experience, it never occurred to me how rare bidirectional interactive pipes are. I assumed it was trivial in my thinking :wink: I started to play with some C++ code in Qt 5.9.1 to hook in your Google Translate and a profanity filter - but right away I found out how complex the bi-dir pipes issue was. I assume you have solved all the pipe issues with your bash trans script. If anyone has two-way interactive pipe C++ code that could run in Qt 5 - please mention. Thank you and great to see stdin/stdout app chaining IF ideas getting attention.

As for why I’m so gung-ho on RemGlk: it offers “channel I/O” in terms of multiple windows of output - and it still text based. So, translate can distinguish the structure of the status window independent of the main story text stream. I think it would be cool if someone could make a CheapGlk that runs on top of the JSON of RemGlk - so that all plugins operate between RemGlk. So, you would chain like:

./remglk_frotz  ./Advent.z5 | ./trans  :fr -b | ./profanity_filter | ./remglk_to_cheapglk

Hmmmm… I hadn’t really been aware of CheapGLK and RemGLK. I’ll have to look into these.

Fall semester is about to start up, so it may be a bit before I can move forward. I’d love to see where anyone else goes with this general idea. :slight_smile:

In Linux, the pipexec program really helps with creating bidirectional pipes.

Speaking of pipexec, this command outputs the text as speach (still have to type in the commands though):

# pipexec [ DFROTZ ./dumbfrotz -p Advent.z5 ] [ ESPEAK /usr/bin/espeak ] "{DFROTZ:1>ESPEAK:0}"

This one outputs the translated text as speech (french espeak voice):

pipexec [ DFROTZ ./dumbfrotz -p Advent5 ] [ ESPEAK /usr/bin/espeak -v fr ] [ TRANS ./trans :fr -b ] "{DFROTZ:1>TRANS:0}" "{TRANS:1>ESPEAK:0}"

It’s great you are discussing Pipes, as that’s really what I keep getting excited about, “plugins”, pipes.

My personal difficult, where I’m frustrated, is that “$ pipexec” is an operating system specific command. How can we make it a generic thing for RemGlk structured JSON data - to work with code like the multiple interpreters of Gargoyle and multiple presentation libraries. In other words, can someone please help out in making a bidrectionay JSON piple example that can work with CMake portable project? Please reference: github.com/cspiegel/terps blinding of multiple layers into a common Makefile system. We need the C or C++ skills of portable code. pipexec sets the example, how can we encourage a plugin standard for Interactive Fiction?

For the record: And I by no means am against webapp solutions, bash pipexec solutions, I express this as a legacy need to forward-thinking being expressed in conversation. I’m wishing, future.