I'm currently testing the following solution:
I've adapted the home.php of my theme (based on Thesis).
By using home.php, browser-preferences are only used to redirect visitors on the site's home.
I've inserted the following before thesis_html_framework(); (in fact, it simply has to be called before HTML is sent to the browser so the redirection works correctly):
if ((substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) != ICL_LANGUAGE_CODE) && (!stristr($_SERVER['HTTP_REFERER'], get_bloginfo('url'))) ) {
$languages = icl_get_languages('skip_missing=1');
if(1 < count($languages)){
foreach($languages as $l){
if (substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2) == $l['language_code']) {
header('Location:'.get_bloginfo('url').'/'.$l['language_code'].'/'); exit;
}
}
}
}
Some comments:
- browser language: substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2)
- current WPML language: ICL_LANGUAGE_CODE
> if preference not equal to current language, consider switch to other language.
- last page the user visited: $_SERVER['HTTP_REFERER']
- root of wordpress installation: get_bloginfo('url')
> if WordPress-url is part of referer-url, the user clicked one of our own links (so we don't automatically switch the language)
> main reason to do so: I didn't want to override manual language selection
- fetch available languages for home
> if content is available in the user's preferred language, rewrite header and forward to selected language-version
Any comments are appreciated, of course. At the moment I'm only using the user's preferred languages and no possible second or third choices. As it's still possible to switch manually, I'm currently quite happy with the hack.