当尝试使用javascript国际化api以挪威语(Nynorsk)语言环境显示datetime值时,我得到了意想不到的结果。
我正在使用挪威语(Nynorsk)语言环境的ISO 639代码,即nn
,但这并不像预期的那样工作。
在浏览器控制台中打印日期时间值的javascript示例代码(Google Chrome,语言:英语)
console.log(
new Date().toLocaleDateString('nn', { dateStyle: 'full' })
)
// output: 'Monday, May 9, 2022'
// expected output: 'mandag 9. mai 2022'
你知道我哪里错了吗?
我是否使用了正确的语言环境代码?我也试过nn-NO
,但结果相同。区域代码no
和nb
工作,但我不能使用它们,因为我猜它们映射到挪威(bokmaul)区域。
您现在可以使用nb
-所有挪威人都能理解bokma
的nn(- no)是一个有效的区域设置-这似乎是一个Chrome的错误
下面的代码可以在Edge浏览器中工作,但不能在Chrome 100
console.log(
new Date().toLocaleDateString('nb', { dateStyle: 'full' })
)
// expected and actual output: 'mandag 9. mai 2022'
console.log(
new Date().toLocaleDateString('nn', { dateStyle: 'full' })
)
// actual output in Chrome: 'Monday 9. May 2022'
// actual output in Edge: måndag 9. mai 2022
// testing this
console.log(
Intl.NumberFormat.supportedLocalesOf(["no", "no-NO", "nb", "nb-NO", "nn", "nn-NO"])
)
// I get [ "no", "no-NO", "nb", "nb-NO" ] in Chrome 100
// and [ "no", "no-NO", "nb", "nb-NO", "nn", "nn-NO" ] in Edge