Webucator Blog

Saying “Hello World!” in your Language using JavaScript

Almost every programming class or book starts with a “Hello World” script, in which students learn to write a small program that outputs “hello world”.  According to the all-knowing wikipedia, this practice dates back to 1974 and was first used in a book on C.

Although there are programmers all over the world who speak many different languages, for some reason, the script always seems to use English (e.g, “Hello world” instead of “Bonjour monde” or any other language).

Just for fun, we’ve decided to create a little script in JavaScript that let’s you choose in which language you would like to greet the world.

Here’s the function:

function sayHello(language) {
	var arrHellos = {
		"Chinese" : "你好世界",
		"Dutch" : "Hallo wereld",
		"English" : "Hello world",
		"French" : "Bonjour monde",
		"German" : "Hallo Welt",
		"Greek" : "γειά σου κόσμος",
		"Italian" : "Ciao mondo",
		"Japanese" : "こんにちは世界",
		"Korean" : "여보세요 세계",
		"Portuguese" : "Olá mundo",
		"Russian" : "Здравствулте мир",
		"Spanish" : "Hola mundo"

And here’s a simple HTML form to call the function:

<form method="get" action="javascript:void()">
    <select name="language" id="language">
  <input type="button" onclick="sayHello(this.form.language.options[this.form.language.selectedIndex].value);" value="Say Hello" />

I used http://babelfish.yahoo.com for the translations.  If you see any that are wrong, please let me know.  Also, if you know how to say “Hello world” in additional languages, please leave a comment to let me know.