Write JavaScript in Other Languages

我只是一个虾纸丫 提交于 2020-01-16 04:15:06

问题


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")

回答1:


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.




回答2:


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




回答3:


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.




回答4:


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.




回答5:


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




回答6:


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.




回答7:


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.




回答8:


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...




回答9:


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.



来源:https://stackoverflow.com/questions/839966/write-javascript-in-other-languages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!