I detect browser language like this:
var language = window.navigator.userLanguage || window.navigator.language
Then I send this value to my webserver with AJAX call.
When I check the results I saw a weird thing. For example user agent of the browser says that current locale is tr-tr
, but when I check for window.navigator.language
I get the result as en
.
All these browsers says that their language is en
:
Mozilla/5.0 (Linux; U; Android 2.2.2; tr-tr; GM FOX Build/HuaweiU8350) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1,
Mozilla/5.0 (Linux; U; Android 2.2.2; tr-tr; LG-P503 Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1 MMS/LG-Android-MMS-V1.0/1.2
Mozilla/5.0 (Linux; U; Android 2.3.4; tr-tr; GT-S5670 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 2.3.6; tr-tr; GT-S5360 Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Mozilla/5.0 (Linux; U; Android 2.3.6; tr-tr; GT-S5830i Build/GINGERBREAD) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1
Mozilla/5.0 (SAMSUNG; SAMSUNG-GT-S7233E/S723EJVKB1; U; Bada/1.0; tr-tr) AppleWebKit/533.1 (KHTML, like Gecko) Dolfin/2.0 Mobile WQVGA SMM-MMS/1.2.0 OPN-B
Mozilla/5.0 (SAMSUNG; SAMSUNG-GT-S8500/S8500JVJE6; U; Bada/1.0; tr-tr) AppleWebKit/533.1 (KHTML, like Gecko) Dolfin/2.0 Mobile WVGA SMM-MMS/1.2.0 OPN-B
Mozilla/5.0 (X11; U; Linux x86_64; tr-tr) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.114 Safari/537.36 Puffin/3.7.0.177AP
Mozilla/5.0 (Series40; NokiaC2-02/07.63; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/5.0.0.0.31
Mozilla/5.0 (Series40; Nokia311/07.36; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/2.3.0.0.54
Mozilla/5.0 (Series40; NokiaC3-00/08.70; Profile/MIDP-2.1 Configuration/CLDC-1.1) Gecko/20100401 S40OviBrowser/2.3.0.0.49
Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; ASU2JS; rv:11.0) like Gecko
Should I consider anything more for browser language detection ?
My problem is detecting browser language. Regarding to user agents, current language is "tr", but window.navigator.language
gives "en". Is it a known problem ? Shouldn't I trust window.navigator.language
value ? Should I parse user agent for language ?
Edit:
I also checked Accept-language header for these requests. These values are consistent with request's user agent string.
So, window.navigator.language
says "en", Accept-language
header is "tr-TR, en-US", user agent string has "tr-tr" word.