Hopefully a quick answer for someone, but my google-fu has deserted me.
In vbscript I can use “setlocale” to set the locale a script is running in. I need a javascript version.
So for example, say my user is using a browser with french settings, but I want numbers and dates to be in english and worked with as if they are english. Then in vbscript I could do
setlocale 2057
to set to english locale
and then when I’m finished working with the numbers/ dates I can set back to french
setlocale 1036
Is there a javascript equivalent? How can I accomplish this in javascript?
No, there’s no way to choose locales in JavaScript.
However, doing stuff in the US English locale is not generally a problem since that’s what JavaScript does anyway. If you handle
Numbers with parseInt, toString and so on you will always be dealing with.for decimal points and there will be no thousands-separator.Datedefault formatting also uses English weekday and month names, and a browser-specific date format that ignores what your locale’s default would be.You have to go out of your way to get anything locale-specific in JavaScript, with methods like
toLocaleString. The results are typically poor and inconsistent across browsers. If you want reliable localisation in your webapps, you have to do it yourself.