5 ms·
Expert advice incoming to alleviate the suffering. How to determine the locale correctly in a Web application: try the following steps, in order. 1. locale pre
by bmn__ 6y ago
Expert advice incoming to alleviate the suffering. How to determine the locale correctly in a Web application: try the following steps, in order.
1. locale preference stored in session of the Web application
2. locale preference stored in user settings of the Web application
3. locale preference advertised in browser
3. a) Accept-Language header
3. b) language/territory in User-Agent header
3. c) IP address lookup/geoip
3. d) Geolocation API
4. default locale of the Web application
You will notice that Google tries to be "smarter", to the detraction of the user, as shown in many comments in this thread.
Implementation notes: 1. and 2. require a locale selection somewhere as part of the Web application, 3. is browser settings, 4. is hard coded in the Web application.
----
From the article:
> Don't set the language of your website based on user location
This is an extreme/absolute prohibition and therefore almost certainly false/useless. Done correctly, user location is one clue in a chain.
> why would I have my machine in that language? And if it's not, I will change it myself.
Sometimes, it is not possible or feasible. Be aware of these situations. Examples:
* You are in an internet cafe or corporate environment and the browser settings are locked down by admin policy.
* You borrow someone else's mobile phone or tablet for a few minutes.
- tvaughan 6y agoAs someone who has traveled and lived abroad the past 10 years, please, never ever use physical location to set the language. Yes, never ever. Why assume everyone at an internet cafe speaks the same language as determined by its physical location? Why assume either person involved in this borrowed tablet situation speaks the predominant language of wherever they happen to be physically at that moment, like a business trip, or vacation? What about VPN's? Use a cookie and Accept-Language, and provide a menu of language choices where each choice is in that language, e.g. Español not Spanish.
- bmn__ 6y agoYou made such a poorly thought out reply, I have already written three drafts in attempts to tackle it and discarded them. I don't have the patience to point out in detail what's wrong with it on a level of discourse that I consider acceptable on HN because it takes an order of magnitude more effort than you put in. I will reconsider and write the proper reply if you really want me to.
- tvaughan 6y agoCould you please post it to https://www.reddit.com/r/iamverysmart/ https://www.reddit.com/r/iamverysmart/?
- XCSme 6y agoI live in the Netherlands, so Google keeps showing me Dutch results first, Dutch videos on YouTube and Dutch ads, even though I don't know Dutch and I did set all my preferences everywhere to English, but it seems to be stubborn to show me Dutch content even though it's just a waste of bandwidth and ad budget.
- marcosdumay 6y agoWell, 3a is always set, so there is no reason ever to fall back into 3b, 3c, 3d, or 4 (unless you are supporting non-mainstream browsers, what does make sense, but the advice is much less wrong than your comment implies).
- bmn__ 6y ago> 3a is always set, so there is no reason ever to fall back It would appear so on first glance, but consider that sometimes, the 3a value is useless, and some home-brew analytics will reveal that; so you can think about whether to not take the value into consideration for the locale. Unfortunately, the real world is messy like that. :( Examples: • browser was never configured because the user does not know how, or even that the capability exists, and hence does not reflect the true intention of the user • browser configuration could not be changed for technical or social reasons • browser is hardened against finger-printing
- marcosdumay 6y agoNothing lower on your list can be changed more easily than accept language. So, if it is wrong, anything lower has a high likelihood of being wrong too. That' why your #1 and 2 are important. And you have no means of knowing that the accept language is wrong anyway. But it's always there (for mainstream browsers), and more trustworthy than the lower options. You won't have the chance of falling back into them. (A non configured browser has that header set, and you don't know if the browser user can change it or is lying.)
- account42 6y agoNot ignoring values from 3a is exactly what this discussion is about. Stop second guessing the user's settings.