5

This question might me hilarious obvious but ... I have searched the web and stack overflow but did not find a satisfying answer.

What makes a good start for adding language selection to a web site?

My urls will be

example.com/de/ example.com/en/

to indicate the current language, plus a cookie set after I determined the initial language.

Upon landing on example.com I will check for a (recent) cookie first, then for ACCEPT_LANG then if a specifiy url is given with /en/, /de/.

The language will always be part of the url to allow bookmarking, i.e. I will redirect to example.com/de/ if I have determined that the users intention is to see the site in German.

Now my question: What is the preferred way these days to signal the server the users choice? I am not talking about the visual selection (drop down vs. language list à la wikipedia) nor geolocating vs ACCEPT_LANG but the user signaling the server. I have in mind: (Assuming the user is on English site and wants to switch to German site)

  1. Do client-side javascript wizardry and alter location.href s//en///de/
  2. Pre-render the language alter link on the server (Would give me a chance to suppress links for non-existing translations)
  3. Post-back to example.com?lang=de&orig= which does the response redirection. Would give me the chance to re-fill form variables if the user decides to switch the language while filling out fields, but I am not certain on this point.

Other possibilities or what is the best technically seen?

3
  • 4. Use a smart default (browser language?) and store any changes by the user in a cookie. Commented Nov 21, 2011 at 21:50
  • "Upon landing on example.com..." : Checking language presence in URL should come first, not last. Commented Nov 23, 2011 at 0:05
  • Regarding solution 3, the server could maybe use the referer instead of an 'orig' parameter. Cleaner and easier to code. Commented Nov 23, 2011 at 0:10

2 Answers 2

1

My personal favorite is along the lines of solution 3 because it means you have a specific 'Change language' request where you can do specific processing, such as saving the preference in the cookie.

Simply using client-side wizardry to modify the URL doesn't tell the server that user actually wants to switch language. It may simply be that user landed on this language-specific page coming from a Google/Bing/Whatever search, in which case, user didn't actively chose a language, hence the choice should not be stored in the cookie.

(I'm not sure I understand what you mean in solution #2. Can you please clarify?)

BTW, pleaaaaase, no geolocation based language selection. I can recognize presto all sites that do that: They display in Dutch because I'm Belgian and 60% of the belgian population are Dutch speakers. Bad luck for the 40% of us French speakers, eventhough our Accept Language is set to French :-(

Sign up to request clarification or add additional context in comments.

2 Comments

By #2 i mean that a serverside script checks whether the requested page is available in, say, German too. If yes, a <a href= ... /de/thispage.html> is rendered. If not -- the language switch is not displayed. A clientside javascript as in #1 would only be able to unconditionally render this links
BTW, I was under the impresion that by #1, assigning to location.href would issue a HTTP GET.
0

Alternatively you could use localStorage key/value pairs, and when the page loads it checks to see if a preference is set, directs them accordingly. Just like cookies they can be purged at anytime, but using local storage does persist across across browser tabs and sessions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.