4

Since last few months I got the problem to detect countryCode from window.navigator.language. My current language on chrome is French(Switzerland)

Currently it return only the language:

window.navigator.language: fr

It was return language-contryCode:

window.navigator.languge: fr-ch

I did a lot of try but currently I cannot detect it from chrome browser. Do you have any idea to solve this problem ? updated: This is my current setting: enter image description here And here is the result from chrome: enter image description here Hope I will get some help. Thank you

Le Dac Sy
  • 381
  • 3
  • 16
  • Possible duplicate of [Retrieving browser language in chrome](https://stackoverflow.com/questions/33204177/retrieving-browser-language-in-chrome) – CBroe Jan 12 '18 at 10:10
  • Not really, since a few months ago, chrome changed their way to get navigator.language, I guess. I will update a picture of my setting language – Le Dac Sy Jan 12 '18 at 10:17
  • This works fine for me, when I try a language like `en-US` - but not for `fr-CH`. – CBroe Jan 12 '18 at 10:30
  • Yes. seems with english - it return that result but not with others – Le Dac Sy Jan 12 '18 at 10:51
  • What are you planning to do with that information anyway? The language the browser is displayed in should usually be of way less importance to you, than the actual language preferences for _content_ the user specified. – CBroe Jan 12 '18 at 10:53
  • Thanks for your answering and questions. Actually we having some application works in Switzerland which country speak difference languages, and the application must adapt that on specific locale. Each locale they have difference day format and number seperator. That's what I need to reach. – Le Dac Sy Jan 12 '18 at 11:15
  • Hm, maybe the `toLocale…` methods of Number and Date objects could be more helpful in that regard …? – CBroe Jan 12 '18 at 11:27

1 Answers1

1

It seems to be a bug, and it has been reported to chromium

navigator.language result differs between english and other languages

PEC
  • 632
  • 1
  • 11
  • 28
  • 2
    In order to distinguish English and German I currently use a work around: (1.1).toLocaleString().substring(1,2) yields the decimal separator "," for German language setting. – Stefan Mar 16 '18 at 08:55
  • Excellent workaround, it will also work to distinguish fr-fr using , (comma) and fr-ch using . (dot) – PEC Mar 16 '18 at 12:14