Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Language selection of web site

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?

like image 434
JohnDoe Avatar asked Nov 13 '22 14:11

JohnDoe


1 Answers

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 :-(

like image 178
Serge Wautier Avatar answered Nov 16 '22 02:11

Serge Wautier