5 ms·
Who uses Accept-Language header?
- atemerev 2y agoThere are many many cases when you can’t determine user’s language by location only (immigrants, VPNs, business trips, multinational corporations, countries where people speak multiple languages, etc). If you do any effort in localization, you should recognize Accept-Language. If unsure, you should ask the user for their preferred language directly. Inferring the language by location is not acceptable. Here in Switzerland, I am so tired of websites offering German localization by default. We don’t speak German in Geneva.
- arielcostas 2y agoAt work we have it implemented as follows: 1. Check if there is a language cookie set previously 2. If no cookie, check if the Accept-Language is present and contains one of the supported locales 3. If no Accept-Language matches, use the fallback application language Not that hard to implement, except perhaps parsing the Accept-Language preferences with their quality value can be cumbersome.
- dotancohen 2y agoHow does the language cookie get set in the first place? Is there any option for the user to set his preferred language?
- maple3142 2y agoIt is a part of browser's settings (for Chrome and Firefox at least), and it is default to system's default language I think.
- JimDabell 2y agoYou’re talking about the Accept-Language header. They are asking about the cookie. To answer the question, yes, normally you would have some kind of manual switcher that sets the cookie. Please don’t use flags for this, because flags indicate countries, not languages. Don’t make a Russian-speaking Ukrainian seek out the Russian flag, and don’t make an English-speaking Irish person seek out the Union Flag.
- rrr_oh_man 2y ago> To answer the question, yes, normally you would have some kind of manual switcher that sets the cookie. Please don’t use flags for this, because flags indicate countries, not languages. Don’t make a Russian-speaking Ukrainian seek out the Russian flag, and don’t make an English-speaking Irish person seek out the Union Flag. Yes, why make things easy. :-) Controversial opinion: Flags are great as a visual aid, shorthand, look neat, and give a better UX for 90+% of users, even if it hurts some linguists' and nationalists' feelings.
- nicolaslegland 2y agoBetter yet: Offer en_CA, en_GB, en_IE, and en_US, with appropriate flags. (Bonus point for fr_CA with the CA-QC flag)
- Cyberdog 2y agoBut then where's the flag for Liberia and Belize and Singapore? What if I'm in Indonesia and you don't offer an Indonesian option but I know enough English to get by - what country's flag should I click? Just don't use flags, man. It's ridiculous that this is even still a discussion.
- tmtvl 2y agoI dunno, which flag would serve as a comprehensible shorthand for Arabic? How many Arabic readers would recognise that flag? How many Spanish speakers would recognise the Spanish flag? If you use flags I would still recommend putting the language name in the language next to it, for example the French flag next to 'Français'.
- shdon 2y agoSame as what we do. Only one additional thing: when people log in to their accounts, it switches to the preferred language for that account (and any changes in language selection whilst logged in are also saved into the account preferences).
- Cyberdog 2y ago> Not that hard to implement, except perhaps parsing the Accept-Language preferences with their quality value can be cumbersome. Many web frameworks provide a tool for parsing these for you. If yours doesn't (or you're not using one) you may be able to find a package that does. Some will also do the matching for you, so you can pass it a list of languages you can support alongside the Accept-Language string and it will pick the best option that's found in both. For example, here's the documentation for such a method in the excellent Nette PHP framework that I've been using where I can lately: https://doc.nette.org/en/http/request#toc-detectlanguage https://doc.nette.org/en/http/request#toc-detectlanguage But I've also used this stand-alone package: https://packagist.org/packages/willdurand/negotiation https://packagist.org/packages/willdurand/negotiation
- LordShredda 2y agoRuby on Rails has built in localization and actually respects whatever headers the user agent sends
- bouke 2y ago`Accept-Language` contain both language and locale. Depending on your app you might have supported languages or language/locale combinations. When there's no exact match after step 2, you'll want to do a partial-match on only the language.
- deleted 2y ago[deleted]
- usrusr 2y agoSpecial mention to Amazon who insist that you want to browse their entire dropshipper directory, on all devices, in the language of whatever you last opened in a non-dubbed version on your TV. (if the original version is even available, they even find ways to offer some BBC shows, of all things, dubbed-only)
- sebstefan 2y agoI get all of their websites in french (correctly) but some of their emails used to always come in german. I don't speak german, I've never set the language to german, I don't think I had even visited amazon.de at that point. Then one day it went away. Complete mystery
- layer8 2y agoFor that reason I use shortcuts/bookmarks of the form https://www.amazon.tld/?language=en_US https://www.amazon.tld/?language=en_US (or whatever your language preference is). If you’re using the Amazon app on iOS, you can open com.amazon.mobile.shopping://www.amazon.tld/?language=en_US, which does the same for the app.
- redleader55 2y agoThere are two situations that I hate: 1. I have a different IP than usual, so all the sites change to that country - including language, news and search results(Google), etc, even though my browser sets a list of Accept-Language options. It's still me, I know you track me, so why? 2. Changing a multi-language website to a different country, also changes the language to that country, even though by browser sends an Accept-Language header and they have the translations for the website from their other sites/countries. I don't suddenly start speaking a different language if I look at a your site from a different country.
- benmanns 2y ago1.b. When somehow they identify you’ve change IPs the first time, and now that you are home, there’s still some sticky session that doesn’t get cleared without purging all cookies for the domain.
- deleted 2y ago[deleted]
- Malidir 2y agoIt's not a high priority task and is in the backlog gathering dust ;)
- epolanski 2y agoI hate it too. Not only languages change, but many other things like date formatting, mathematical formatting (using commas rather than dots breaks few things around) and currencies too! And it's a pain to fix as settings often collide and with many applications abusing microfrontends you can even end up in conflicts on the very same pages. Google's the worst offender on all of its services and not just search, youtube, etc (even for work, their forced localization breaks Google Sheets in multiple ways), even my goddamn portoflio prices get converted in the local currency or using google flights shows me prices in the local currency forcing me to open more tabs to convert non stop. And changing it to my own, on so many different services is such a pain. But I know why this happens as a developer who advocated multiple times with my managers to not forcefully try to compute the language/region/market of users without giving them a simple button flag to change locale: product people don't listen and would rather have thousands of "ifs" that eventually will fail rather than listen to reason. Hell, as a developer I have all my software and preferred language to english, even though I'm italian. And sometimes I use VPNs! Even Amazon at times gives me some text in a language, and some other in others (completely unrelated like German) on the very same page. Just keep it simple.
- JimDabell 2y ago> Interestingly, Google does respect the Accept-Language header. While testing in Yelp domain, Google Sign-In widget popup appeared in Japanese. I’m surprised by this. In my experience, Google are the one big organisation that I can count on to get this completely and utterly wrong. I’ve lost count of the number of times I’ve been stuck with a Google interface, popup, or some other thing that is in a language I don’t speak, just because I was visiting another country. I’ve specifically encountered it repeatedly with the very Google Sign-In widget they say works for them. Sure, if it happens to be a Google website and you know the magic incantation of &hl=en then you can sometimes work around it, but that doesn’t help when it’s a Google login from another website or something of that nature.
- nonamesleft 2y agoIndeed, google never behaves for me, always hands me language localized to my ip, even though my Accept-Language contains "en-US,en;q=0.9" (the local language is my native one, but i find using services or software that are originally in English translated to my (non-PIE) language awful, even anger-inducing). For search i have had &hl=en added to the search parameters since forever.
- distances 2y agoWhat works surprisingly often is setting language to en-UK instead. Apparently many sites consider en-US to be some default that they can safely ignore, but en-UK to be a deliberate choice. Nowadays I use that not just for the browser, but for my phone and computer too.
- zarzavat 2y agoI can say that it doesn't work on Google Docs, which uses the IP address's language^, even though my language is set to en-UK. Unless you're logged in, but I often have to use incognito because of another misfeature which is that Google will dox you to other editors if you access a public Google doc while logged in. Googlers reading this comment: please fix this! ^ I wonder how this works in places like Switzerland and Belgium that have more than one language. The notion that IP addresses can be mapped to languages needs to die.
- iwwr 2y agoThis is a problem for me as a language learner on mobile. I set a keyboard with (for example) Russian, and suddenly the world looks Russian, even though I am far from comfortable in it yet. I wish there were a way for the browser to ignore some system languages. This is worse for apps because I also get served with localised versions, where I need to uninstall, remove system language and re-install.
- tlhunter 2y agoThis drives me nuts when I visit foreign countries with a language I don't speak and then the internet stops working. My browser literally tells the server I speak but 90% of the content I get back is suddenly in the wrong language.
- mrweasel 2y agoEven Accept-Language headers aren't really a particularly good solution. I might prefer some sites in Danish, but others I'd like to have en English. Unless browsers allow you to set language on a per site basis, we still aren't really capturing the nuances of language preference. Accept-Language could be a pretty good indicator of a persons language skills, but it's just to far into the browsers settings to be something that a normal user would adjust. I can see why checking the domain is quicker and perhaps more inline with a persons intent, even if it is ignoring travelling. We where trying to book a table at a restaurant, it's part of a fairly large chain. We where in Sweden, but the chain also operates in Denmark, so we know that they have a Danish version of their website and ordering app, you just can't use the Danish language when you are in Sweden. You can get English for some reason, but not the Danish version. That to me seem like a missed opportunity.
- simonw 2y ago> but it's just to far into the browsers settings to be something that a normal user would adjust. Most users are on mobile these days, and picking your preferred language is an unskippable step of setting up a new phone. My hunch is that accept-language is far more accurate today than it used to be.
- myfonj 2y ago> […] picking your preferred language is an unskippable step of setting up a new phone. This does not address, or more precisely it even prevents the notion of: > I might prefer some sites in Danish, but others I'd like to have en English. , i.e. what you set in your OS or UA (browser) is always one preferred and optionally some fallback languages. I second that granular per-site control would be preferable for me either: some texts I prefer in my mother tongue (news, non-tech encyclopedic articles), the rest, namely technical documentation I prefer in English. (Also, I have very bad experiences with localised GUIs, where 1. familiarity with English "original" vastly helps when searching and 2. translations tend to range from bad to hilariously comical.) But I must admit that most websites serving of content in multiple languages, support client-side pref pretty well, so the situation is not so terrible, in my experience. Yet, the problematic of content negotiation and user <-> agent <-> author (provider) information passing is interesting and I'd say even under-engineered, and currently terribly suffer from security (anti-tracking) constraints. (Lately, there was some development in "Client Hints": https://developer.mozilla.org/en-US/docs/Web/HTTP/Client_hints https://developer.mozilla.org/en-US/docs/Web/HTTP/Client_hin... )
- allenap 2y ago> Interestingly, Google does respect the Accept-Language header. Google knows I use/want English. It knows this because I'm logged-in and have set my preferences, but also because of that Accept-Language header my browser sends in every single request. Yet for years, perhaps because I am 20km from Germany, it has assumed I would always prefer German when doing social sign-in. Google may occasionally glance at Accept-Language, but it does not respect it. It even demotes my own logged-in preferences below a guess based on my location. When there are no other indicators, fine, guess my language from my location, but otherwise location != language. But I know for fact that my browser is sending out Accept-Language headers in a convenient format that will tell you all you need to know.
- bhaney 2y ago> we were able to mitigate the problem simply by adding Accept-Language header > Yelp doesn't actually use the header So what made you think to add it and why did it work?
- ivan_gammel 2y agoI always design i18n with a preferred language on a customer profile and I use Accept-Language to pre-select it on registration. Browser settings must be respected, of course, but there are also non-browser communications that can use this preference. It is very small amount of work if done at the start of the project rather than as feature upgrade.
- throwaway2016a 2y agoIn my experience Accept-Language header is pretty unreliable. It tends to just be one of a few values. Between people never updating it, proxies stripping it, people concerned it will make them easier to fingerprint, etc. Also, form an implementation standpoint, translation is a lot of work to get right and some companies may not do it for all languages so they may support the header but just not support the language choice you have. Yelp being a weird example where they apparently have the Japanese translation on another site. Combine all that together and it's not usually worth the effort to do it unless you have specific legal requirements or high demand from users.
- cdaringe 2y agoProxies stripping it? Tell me more.
- throwaway2016a 2y ago(Sorry for the delay, I haven't checked HN is a while and just noticed this) So some proxies (forward and reverse) will strip this header for different reasons. The reverse proxies sometimes strip it to improve caching and/or because they were configured to have a allow-list of headers and this (being a less common one) was excluded. The forward proxies will sometimes strip it for privacy reasons (it can be used in fingerprinting) or for the same reason (they have a list of allowed headers and this isn't one).
- diego_sandoval 2y agoQuestion: Can you include two languages with the same level of preference in the Accept-Language header? The idea is that the website chooses which language (between those two) to use.
- layer8 2y agoUnfortunately not. I’d really like to have the semantics of “the website’s native language if I understand it (if it’s one of A/B/C), otherwise English”. But nowadays it’s a clusterfuck anyway. You often get WebView-based apps were half of the UI uses the OS language, half the browser preference, and the third half the service’s native/local language.
- Cyberdog 2y agoThe Accept-Language header, when used properly, provide exactly the semantics you ask for.
- cdaringe 2y agoThere’s ambiguity in the spec in selection itself. f(a-l-input, supported-locales) yields different outputs contingent on what selector youre using, and its not incorrect
- Cyberdog 2y agoYes, but if the web site supports both of them, then it will pick whichever one is first in the header. For example, "en;q=1.0,de;q=1.0" technically states you want equal weight to be put on English and German, but the site has to pick one to show you, so it will most likely fall back to the behavior that's used when the quality score isn't provided (such as "en,de"), which is to pick the first one it can service from left to right.
- krzyk 2y agoYeah, but Accept-Language is not always good idea. E.g. I prefer to view some websites in English and some in my native. Generally I prefer all the websites that are not from my country domain to be in English. Setting up Accept-Language per website is annoying. The most annoying part is when my local website sees "en" there, and decides to show me English version. It is easier to just add e.g. `.jp` to domain, than to find out where browser sets up Accept-Language.
- donatj 2y agoWe did. I built a parser for the header weights and what not. It was a fun project and I thought the results were really slick. It was also easily overridden by a very large language picker in our footer. This override choice is remembered in a long lived cookie. People complained. They didn't understand why they were getting whatever language and the picker was apparently too hard to find. Now we just default everyone to English. They're still free to use the language picker. No one complains.
- LinAGKar 2y ago>It’s great that the solution works, but I’m still curious about the reason behind it. Which the rest of the article doesn't even attempt to examine.
- deleted 2y ago[deleted]
- tracker1 2y agoI've worked on a couple multi-language/location projects... Usually using the Accept-Language header as the default response to closest match or the default language (en-US fallback). In which case, I would allow for a cookie and/or url override that would set a cookie and redirect. https://en-gb.foo.com >> set cookie and redirect to bare domain ...?lang=en-GB >> set cookie and redirect without the lang portion <cookie> <Accept-Language Header> I'm also a proponent of having a mini-flag for the current language as a dropdown/flyout menu in the upper-right of the header where each local/language has the appropriate flag/representation in addition to the language name IN that language. You can use just language (en) instead of language+locale (en-US) as desired. edit: also, make sure you set your cache directive to include the cookie/header in question. You can also work the other way and always use the locale for subdomain.