I’ve been fiddeling around with this issue for quite some time already. I want to be able to retrieve month names and day names from the users locale settings. I’ve come up with some code, using the Date.toLocaleDateString() method:

function diffArray(arr) {

for (var i = 0; i < arr[0].length; i++) {

for (var j = 0; j < arr.length – 1; j++) {

if (arr[j][i].length && arr[j + 1][i].length && (arr[j][i] != arr[j + 1][i])) return i

}
}

return -1

}

function setLocaleNames(arr) {

var tmp = new Array();

for (var i in arr) {

tmp[i] = arr[i][diffArray(arr)].replace(/[\,\.]/g, “”)

}

return tmp

}

function setLocaleMonthStrings() {

var tmp = new Array();

for (var i = 0; i < 12; i++) {

var d = new Date(new Date().getFullYear(), i, 8);
d.setDate(d.getDate() – d.getDay());

tmp[i] = d.toLocaleDateString().replace(/\d/g, “”).split(” “)

}

return tmp

}

try {

/* Try to retrieve locale month names… */
var nameMonth = setLocaleNames(setLocaleMonthStrings())

}
catch(err) {

/* …else use… */
var nameMonth = new Array(“January”,”February”,”March”,”April”,”May”,”June”,”July”,”August”,”September”,”October”,”November”,”December”)

}

function setLocaleDayStrings() {

var tmp = new Array();

for (var i = 0; i var arr = setLocaleMonthStrings().
For day names, use 7 dates, while making sure that the day of week is unique, but the month is the same for all.
==> var arr = setLocaleDayStrings().

Second, from these arrays, retrieve those fields that are different into another array, getting rid of points and comma’s in the process, using the diffArray(arr) function to find out which index must be used.
==> var nameArray = setLocaleNames(arr).

Since these functions are not flawless (yet ;-), I use try {} catch(err) {} to default to English locale names in case of errors.

Feel free to use, comment, improve.