views:

352

answers:

9

I have some clients who are not English speaking. They would like the JavaScript I write for them to be in another language.

Can browsers understand other languages, or am I limited to non-English comments?

navigateur.nomApp.indice("Microsoft")

Instead of :

navigator.appName.indexOf("Microsoft")
+23  A: 

JavaScript's keywords are in English and browsers' object names are in English. You can't get around this. Even if all of your variable and function names are in French, you'll still need to have English keywords lying around. Your clients will have to live with this.

Welbog
Great idea about the variables and function names.
Jenko
The best thing you can do is heavily document the code with the foreign language. As Jeremy has said, using descriptive variable and function names (also language specific) will also help.
cballou
A: 

You are perfectly able to write your own variables, functions and APIs in other languages; however, the vast majority of existing APIs are going to be in English and there is no way for the browser to understand that you ment navigator when you write navigateur.

Ostensibly, you could write a translation framework that would translate French keywords and French API calls into their English counterparts, but that would be a whole lot of work.

Aaron Maenpaa
Great idea about translating it. I'm thinking server-side translating before sending the script file.
Jenko
Wasabi anyone? http://www.joelonsoftware.com/items/2006/09/01b.html ;)
micahwittman
+10  A: 

You can get any object and assign it to a variable with a French name for instance

var nomAppDeNavigateur = navigator.appName;

Then use it wherever, it's just the keywords that are restricted to Javascriptish. It still has to make sense though, whatever language you are aiming for.

Mark Dickinson
Great idea about the variable and function names.
Jenko
I suppose you could end up with a mini api for the target language, but it would be so specialised, I can't see how it would help in the long run. Whenever you go outside the API you would face a bad learning curve.
Mark Dickinson
+1  A: 

Programming language keywords are fixed. The browser can't translate them from one spoken language to another. Functions you create yourself can be in any spoken language you chose.

Bill the Lizard
+4  A: 

I highly suggest you do not do this. I also think this is not possible. Not only are you throwing away tons of documentation which uses only english but you are making it very difficult for non-french speaking people to code with your application.

See Jeff Atwoods post about this here:

The Ugly American Programmer

Peter D
Who cares about the non-French when everybody's French :)
Jenko
I speak french myself and work in a french environment. But not one coder here would ever consider writing code in french, what if you hire someone who isn't french?
Peter D
+1  A: 

In JS as in any other language you can define your own classes/methods in the language you want but the standart libraries are usually written in english so that's what you have...

ktulur
+21  A: 

JavaScript isn't written in English, it's written in JavaScript.

Adam Jaskiewicz
+1 for telling it like it is.
Welbog
Sadly, its true.
Jenko
Not sad at all. Can you imagine a programming language written to approximate English? You'd have crap like "MULTIPLY PRICE BY UNITS GIVING COST."
Adam Jaskiewicz
What about AppleScript?
Justin Johnson
+3  A: 

Most programming languages are based off of the English language.

As Jeff pointed out in a recent blog post, Eric Raymond notes that functional English is required for true hackers:

Back around 1991 I learned that many hackers who have English as a second language use it in technical discussions even when they share a birth tongue; it was reported to me at the time that English has a richer technical vocabulary than any other language and is therefore simply a better tool for the job. For similar reasons, translations of technical books written in English are often unsatisfactory (when they get done at all).

On a related note, also pointed out in Jeff's post, Wikipedia keeps a list of non-English based programming languages.

Either your client must learn basic English or they must use a non-English based language.

T Pops
It's true. I've had to describe simple systems in Spanish before, which didn't work out to be brief or nearly as simple as in English.
Justin Johnson
+3  A: 

JavaScript is a dynamic language that responds well to monkey-patching:

String.prototype.indice= String.prototype.indexOf;
navigator.nomApp= navigator.appName;
window.navigatrice= navigator;

Et voilà! Your code fragment works as-is. Well, except for the curious way your browser is masculine.

PS. Don't do this.

bobince
+1 for the postscript.
BalusC
I can't upvote this enough. Especially for the PS
Justin Johnson
Hmmm... needs more regex parsing and a dash of eval() ;)
micahwittman