qtranslate-xt
qtranslate-xt copied to clipboard
How to redirect website to non default language
Issue by manhsangtao
Friday Aug 11, 2017 at 09:46 GMT
Originally opened as https://github.com/qTranslate-Team/qtranslate-x/issues/530
Dear all!
i have a issue as bellow My website has 2 languages: en & ja (ja - default language) when language's browser diffirent with EN & JA, i want to redirect to non default language is EN
i was added function. but website has been loop redirect
add_action( 'wp_head', 'browser_redirect', 0 ); function browser_redirect(){ global $post;
$browser_language_code = substr( $_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2 );
$active_languages = qtranxf_getLanguage();
$reffered = @$_SERVER['HTTP_REFERER'];
if ($browser_language_code == 'ja') {
if($browser_language_code !== $active_languages && !$reffered){
wp_redirect(site_url($browser_language_code));
}
}else {
wp_redirect(site_url('en'));
}
}
I was researched but nobody have issue like me. Please help. Thanks a lot
I'm also interested to a solution.
@hacaro76 I don't understand the problem in the first post, could you explain?
In the given example, there are two languages: en
and ja
(default). If the browser doesn't detect either, the redirection will use the default. If you want to redirect to en
by default, then put it as default. Otherwise, why would want to set the default to ja
? 🤔