Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

DateTime Internationalization not working for Norwegian (Nynorsk) locale

When trying to display the datetime value in Norwegian (Nynorsk) locale, using the javascript internationalization api, I get unexpected results.

I’m using the ISO 639 code for Norwegian (Nynorsk) locale, which is nn, but that does not work as expected.

Sample javascript code to print datetime value in the browser console (Google Chrome, language: English)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

console.log(
  new Date().toLocaleDateString('nn', { dateStyle: 'full' })
)  
// output: 'Monday, May 9, 2022'
// expected output: 'mandag 9. mai 2022'

Any ideas where I’m going wrong?

Am I using the correct locale code? I’ve tried nn-NO as well, but same results. The locale codes no and nb work, but I can’t use them since I guess they map to the Norwegian (Bokmål) locale.

>Solution :

You can for now use nb – the bokmål date is understood by all Norwegian

the nn(-NO) is a valid locale – it seems to be a Chrome bug

the code below works in Edge browser but not in 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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading