JS-i18n: JavaScript in your language

JavaScript is an English programming language. If you're a native English speaker, this is fine and dandy. But 95% of the World's population aren't native English speakers. For us, learning JavaScript starts with an intensive foreign language course. In some countries you need to learn a second alphabet as well. Imagine having to learn a few hundred words of Arabic just to make a web page.

The foreign language requirement tends to push up the age when we start coding. I could read Finnish before I started school. Getting to a decent level of reading English took a dozen years on top of that. Sure, I was cargo-culting some code in the meantime, but reading the APIs and documentation was difficult.

Even more important than delaying learning, the foreign language requirement also impedes learning. If you want to program but aren't super hot at languages, the foreign language may well make you skip the whole thing. But if the programming language is speaking your language, maybe you'll give it a go.

Programming in a second language isn't just a hurdle for learning, it also slows you down. You can't think as fast in a non-native language. If your brain's running in Finnish, thinking about code in English is like running emulated code.


First, add the JS-i18n script to your page:

<script src="js-i18n.js"></script>

Next, create a script tag with type="text/js-i18n" and lang="fi" (replacing "fi" with your desired locale, naturally). You're now ready to write localised JavaScript. You can also add the quoted string "lang fi" at the start of the localised JavaScript file to set the script's locale.

<script type="text/js-i18n">
  "lang fi";

  hälytä("Terve maailma!");



Tech details

This script parses JavaScript from a localised version to executable JavaScript. When you click "Run", the localised JavaScript in the left box is executed. You also get a translation of the code in the right box.

You should also take a look at this automagical demo that translates and executes localised JavaScript files. The localised JavaScript files use type="text/js-i18n" to tell the browser not to execute them without translation. The translation library js-i18n then seeks out all the text/js-i18n scripts in the document and runs them.

The translator works by substituting defined keywords and identifiers for their translated versions. It's not perfect, but it's surprisingly comfortable. The Arabic translations is quite broken due to mixed LTR and RTL writing directions, which the translator doesn't handle. The non-Finnish translations are from BabylScript, which is an awesome JavaScript translation project that you should check out.

Fork me on GitHub