Viewing 10 replies - 1 through 10 (of 10 total)
  • Plugin Contributor Alex Gor

    (@alexgff)

    Hi, is there any news about this scheduled functionality?
    By the way, I wrote a few lines of code to temporarily provide a solution.

    It checks only the browser’s language settings, not the navigator or the GEO ip. In every case it works. I put it at the beginning of the header.php of my theme…

    <?php
    	$langs=explode(",",$_SERVER['HTTP_ACCEPT_LANGUAGE']);
    	if(!is_array($langs))$langs=array($langs);
    	foreach($langs as $l){
    		$reallang=(strlen($l)>2)?strtolower(substr($l,0,2)):strtolower($l);
    		if(!class_exists('WPGlobus'))break;
    		$currentlanguage=WPGlobus::Config()->language;
    		/*echo "Testing browser lang $reallang<br>Current language is $currentlanguage<br>";*/ //DEBUG
    		if($reallang==$currentlanguage)break;
    		foreach(WPGlobus::Config()->enabled_languages as $lang) {
    			if($lang==$reallang)header("Location: ".WPGlobus_Utils::localize_current_url($lang));
    		}
    	}
    ?>

    @lucafavorido

    Yes, that code looks OK (with some minor changes, line checking for class_exists before doing all this, and not in the loop; exit after header, etc.).

    However, I do not believe it’s a universal solution. You are forcing people to read in their language. What if I want to switch to another one? What if that specific page is available only in one language? And so on.

    And by the way, your loop should probably check something like array_diff or intersect instead…

    Thanks for posting this!

    Thanks Gregory (@tivnet), I really appreciated your corrections, I’m not an experienced PHP developer, I will surely do the suggested minor change.

    I agree that it’s not the right way to translate pages. Forcing the user to get a language is a despotic behaviour. =)
    Unfortunately the customer isn’t always right and he wants silly things.

    most people are just lazy

    showing the page per default in the language of their browser is a must have

    they could change still manually

    1. There are potential SEO implications.
    2. Not every post is translated into all languages. (See WPGlobus Plus)
    3. WPGlobus’ business is to provide the mechanism for entering the multilingual texts. Detecting user’s language is a different task and should go do a different plugin, IMHO. There are existing plugins for IP detection, language detection and so on. I believe, we could interface with them. So, please try those plugins, see if they work – and then let us know, and we’ll go from there.

    Thank you!

    Hi there. The code of @lucafavorido works but, I need the option to change lang manually, if my browser is spanish okey, but if I want to see the content in english… You know! So please, put here the correct code. ??

    I’m with you, livingflame. The FAQ said that WPGlobus were working on adding autodetection features, but that was in May 2015. Is this still on the roadmap?

    @craigedwardson Not for any nearest future. Read the notes above. Not everything is straightforward. And – again – there are plugins for that. We better interface with them than invent our own wheel.
    Thank you!

    Update:

    Since the version 1.8.0, WPGlobus supports automatic redirect for the first-time visitors. We have the WPGlobus Plus “draft” problem resolved and we believe that Google is smart enough to index all the pages (to be confirmed). Read the details below:

    https://wpglobus.com/news-archive/automatic-first-time-redirect-based-on-browser-language/

    Thank you!

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Auto detect browser language’ is closed to new replies.