Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to store selected language on multilingual site: session/cookies or url?

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:

  1. Detect language and store it in cookie/session and allow switching language (and also store it in cookie/session)
  2. Use detected language if there is no language specified in url, and show links to url with different language
  3. Use default site language and show links to other languages

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.

like image 554
tig Avatar asked May 05 '10 15:05

tig


1 Answers

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.

like image 50
BalusC Avatar answered Jan 07 '23 19:01

BalusC