Christian Heilmann

Rickrolling Google translate with YQL – Rickrollwhisper

Wednesday, August 5th, 2009 at 1:07 am

This morning I found this wonderful blog post that shows what happens when you run the “never gonna give you up” aka. RickRoll lyrics through an automated translation tool and back into English.

This has been a classic time waster using Babelfish in the past for me and I thought we could knock it up a notch and used YQL and the Google Translation API to automate this process.

Check out Rickrollwhisper to see the results.

Rickrollwhisper

Google Translate is one of the Open Data Tables built by the outside community for YQL and you can use it simply by providing a source text and the language to translate to:

select * from google.translate where q="this is a test" and target="de";

Try it out for yourself or see it in the console.

The result is the text as a translatedText element:




true



185
178
2426


Dies ist ein Test

Using this, I simply took an array of supported languages and took a random one each time I translated the lyrics:

$lyrics = "We're no strangers to love,
[…]
I just wanna tell you how I'm feeling,
Gotta make you understand";

$target = getlanguage();
$t = getstuff($lyrics,$target);
$trans1 = '

'.$t.'

'. '

Language: '.$target.'

'; $target2 = $target; while($target2 == $target){ $target2 = getlanguage(); } $t = getstuff($t,$target2); $trans2 = '

'.$t.'

'. '

Language: '.$target2.'

'; $result = getstuff($t,'en'); function getlanguage(){ $languages = array('it','nl','fr','de','sv','pl','ro'); return $languages[rand(0,sizeof($languages)-1)]; } function getstuff($text,$target){ $root = 'http://query.yahooapis.com/v1/public/yql?env='. 'http%3A%2F%2Fdatatables.org%2Falltables.env&format=json&q='; $yql = 'select * from google.translate where q="'.$text.'"'. ' and target="'.$target.'"'; $url = $root.urlencode($yql); $curl_handle = curl_init(); curl_setopt($curl_handle, CURLOPT_URL, $url); curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2); curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1); $buffer = curl_exec($curl_handle); curl_close($curl_handle); if (empty($buffer)){ return 'Error retrieving data, please try later.'; } else { $json = json_decode($buffer); $result = $json->query->results->translatedText; return $result; } }

Maybe I find the time to create the multitranslate as an open table to make this more generic.

Tags: , , , , ,

Share on Mastodon (needs instance)

Share on BlueSky

Newsletter

Check out the Dev Digest Newsletter I write every week for WeAreDevelopers. Latest issues:

Don't stop thinking, AI Slop vs. OSS Security, rolling your own S3 Despite AI you still need to think, Bitter lessons from building AI products,  AI Slop vs. OSS security and pointer pointer…
200: Building for the web, what's left after rm -rf & 🌊🐴 vs AI What remains after you do a rm -rf? Why do LLMs know about a seahorse emoji? What image formats should you use? How private is your car?
Word is Doomed, Flawed LLM benchmarks, hard sorting and CSS mistakes Spot LLM benchmark flaws, learn why sorting is hard, how to run Doom in Word and how to say "no" like a manager.
30 years of JS, Browser AI, how attackers use GenAI, whistling code Learn how to use AI in your browser and not on the cloud, why AI makes different mistakes than humans and go and whistle up some code!
197: Dunning-Kruger steroids, state of cloud security, puppies>beer

My other work: