I have a site that has all its content translated to multiple languages and has no accounts (to set prefered language there). I can detect preferred language using Accept-Language, ip or anything else. I have 3 ways to store user language selection:
Storing langage in url can be of any type: different domain, subdomain, or somewhere in url
I think about first case as it allows me to send one url to anyone and it will be presented to them in their preferred language. But another opinion is that different language means different data, so it must have different link.
Store it in the URL as part of pathinfo, preferably as close as possible to the domain name. E.g. http://example.com/en/page
or http://en.example.com/page
. It's not only SEO friendlier, but it is also guaranteed to work with cookie/session-less clients.
You can also choose for a combination. If the client supports cookies, you could make use of it to store the "preferred" language. If this information is absent in the session, then redirect to an URL which displays the language which matches the Accept-Language
header the most and store this language in the session (which is in most programming languages/frameworks by the way already backed by a cookie). If the user changes this information, then reflect the change in the session as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With