Wrong language detected when using Javascript navigate method

Viewed 360

I 'm building a React JS website and got stuck on an issue relater to the navigator problem. My default browser is Chrome and using English as a language. When I log navigator.language it gives me "he-IL", which I do use but not as default language. In the navigator.languages i get the following array:["he-IL", "en-US", "en", "he"].

Is there a way to set it to detect English only when using navigator.language? Or do I have to get it from the array?

2 Answers

I suppose the default language being used at the navigator function is user-specific, it returns an array of DOMStrings representing the user's preferred languages. You tried returning the array list of languages associated?. In the returned array they are ordered by preference with the most preferred language first.

The property can be changed easily by changing the browser settings. Currently, I think your default is he-IL, so need to change the default to English.

Mine works fine and the

navigator.languages returns ["en-US", "zh-CN", "ja-JP"]

I had the same problem, so I landed on this page...

It seems that even if a language is set as default, navigator.language will return always the first language on the list.

You can easily reorder your list of used languages and put your "default language" on first position. ;-)

Related