Javascript in language other than english
var d = new Date();
document.write(d);
What will it pr开发者_JAVA百科int. It normally prints time of local machine. Will it print time in French language if machine's language is French?
Or is JavaScript outputs just in English?The contents of all Date.prototype.to*String
methods are implementation-dependant (a la the standard in section 15.9). They are however based on an ISO representation which is in English. So basically, the default is always English. When it comes to Date.prototype.toLocale*String
methods the standards say the string should be one that
corresponds to the conventions of the host environment‘s current locale
However there are still some implementation differences:
In FF 4:
Date.prototype.toLocaleString()
uses the OS settings.
Date.prototype.toString()
is always in [American] English.
While in Chrome 14:
Both are always English. This has already been noticed.
Test for yourselves: http://jsfiddle.net/USJeE/
Javascript will output the date in english usually, as far as i'm aware.
You could build your own small library to rename English day names to French day name, so as with months, etc...
You could also try and use toLocaleString but i'm not sure it would do the job. I think it would be easier to implement your own set of "replacement" strings.
Shai.
精彩评论