HACKER Q&A
📣 Ayesh

How do you detect user language in web sites


Hello HN, I'm interested to hear how would you configured your web apps and web sites to detect visitor language.

I currently use the Accept-Language header, most of the browsers appear to just use `en-US` as the default. I am not sure if default installations in various countries have different default settings (for example `de-DE, de` if you download Firefox from Germany).

Second, I could use a small IPGeo database to determine the user country and map it to locale/language, but I really don't want to do it because it's not very user-friendly to those who travel or simply prefer English.

I will of course have a language select list and save this preference, but I'm interested to hear how I can make it user-friendly and do some guess work for the user without being annoying to those who prefer English as opposed to the what my app _think_ based on the location.


  👤 Normille Accepted Answer ✓
We had a discussion about this kind of thing and associated pitfalls, a couple of weeks back:

https://news.ycombinator.com/item?id=23216502

After the hassles I've had with Yandex Browser [as mentioned in the above] I'd say; don't try and detect it. Let the user select their preferred language.

Or, if you really insist on trying to be clever by detecting user language --for the love of all that's holy, give the user an easy way to change it if [when!] you get it wrong!

Few things more annoying that a page which loads in the 'wrong' language and then, even if you select the 'right' one, automatically reloads the wrong one again, because the developer wanted to show off some fancy "I know what you want better than you do!" scripting.


👤 Etheryte
As an expat living abroad, please don't do this. Your webpage doesn't know better than the user's settings, there are few things more annoying than sites that automatically redirect you to another subdomain based on your location. Luckily, the right thing is the easy one in this case, simply add a language picker to your site.