Hacker News new | past | comments | ask | show | jobs | submit login

Quoting MDN https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Ac...

> This header serves as a hint when the server cannot determine the target content language otherwise (for example, use a specific URL that depends on an explicit user decision). The server should never override an explicit user language choice. The content of Accept-Language is often out of a user's control (when traveling, for instance). A user may also want to visit a page in a language different from the user interface language.

So basically: don't try to be too smart. I'm more often than not bitten by this as someone whose browser is configured in English but often would like to visit their native language. My government's websites do this and it's infuriating, often showing me broken English webpages.

The only acceptable use would be if you have a canonical language-less URL that you might want to redirect to the language-scoped URL (e.g. visiting www.example.com and redirecting to example.com/en or example.com/fr) while still allowing the user to manually choose what language to land in.

If I arrive through Google with English search terms, believe it or not, I don't want to visit your French page unless I explicitly choose to do so. Same when I send some English webpage to my French colleague. This often happens with documentation sites and it's terrible UX.






"Accept" specifies a MIME type preference.

You said accept headerS and since the thread was about localization I assumed you meant Accept-Language.

To answer your comment: yes you should return the same content (resource) from that URL (note the R in URL). If you want/can, you can attend to the Accept header to return it in other representation, but the content should be the same.

So /posts should return the same list of posts whether in HTML, JSON or XML representation.

But in practice content negotiation isn't used that often and people just scope APIs in their own subpath (e.g. /posts and /api/posts) since it doesn't matter that much for SEO (since Google mostly cares about crawling HTML, JSON is not going to be counted as duplicate content).


Why are XML and JSON alternates of the same resource but French and German are two different resources?

Because the world is imperfect and having URLs instead of using content negotiation makes a far better user and SEO experience so that's what we do in practice.

IOW pragmatism.


Giving the content in the user agent's configured language preference also seems pragmatic.

In what way is ignoring this pragmatic?

https://developers.google.com/search/docs/specialty/internat...

> If your site has locale-adaptive pages (that is, your site returns different content based on the perceived country or preferred language of the visitor), Google might not crawl, index, or rank all your content for different locales. This is because the default IP addresses of the Googlebot crawler appear to be based in the USA. In addition, the crawler sends HTTP requests without setting Accept-Language in the request header.

> Important: We recommend using separate locale URL configurations and annotating them with rel="alternate" hreflang annotations.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: