JavaScript's standard API to get the runtime's default locale?
I'm not aware of a more straight-forward approach, but as you have already pointed out,
new Intl.NumberFormat().resolvedOptions().locale
is a solutionDefaultLocale
is an abstract operation, which might or might not be implemented in the future.
Hence, I would argue for polyfilling this function
as:
if (typeof DefaultLocale === "undefined") {
function DefaultLocale() {
return new Intl.NumberFormat().resolvedOptions().locale;
}
}
So, your code will reasonably assume the existence and call this function
. In some point in the future, when this function
is implemented in a standard manner, you will be able to clean up by removing the chunk from above.