Support » Everything else WordPress » How to add a Language detection hint?

  • Resolved Aria

    (@ariasg)


    I don’t want to redirect users according to their browser language, no. I want to add an explicit hint.

    I’m working on a multilingual (thus multisite, using the Multisite language Switcher plugin) website with WordPress.

    I’ve seen there are plenty of tutorials in php for language detection, mainly from the user’s browser. I quite understood how to do that, but these techniques usually force or redirect users to another web site.

    I want them to read the page in the current language, but simply indicate that a version of the site exists in their language.

    I would like to add a hint, a bit like when a user w/ a browser in Portuguese visits the English wordpress forum for example (see example).

    Any answer is welcome of course, and could you please point some tutorials to better understand that? Thanks!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Ipstenu (Mika Epstein)

    (@ipstenu)

    Lead Plugin Wrangler

    I’ve seen there are plenty of tutorials in php for language detection, mainly from the user’s browser. I quite understood how to do that, but these techniques usually force or redirect users to another web site.

    Use the PHP for detection, and then instead of the redirect at the end, use it to display content.

    Aria

    (@ariasg)

    Thank you Ipstenu, I’m going to give it a try, there is a first time for everything!

    Aria

    (@ariasg)

    Goodness gracious, Ipstenu! that’s tough…
    I really don’t know how do that.

    I would like to detect Portuguese, French, Italian and Spanish – the default is English.
    Here is the php code I use.
    Unfortunately, I ignore how to retrieve the first 2 letters from the browser.

    <?php
    function detectlanguage() {
        $langcode = explode(";", $_SERVER['HTTP_ACCEPT_LANGUAGE']);
        $langcode = explode(",", $langcode['0']);
        return $langcode['0'];
        }
    
    $language = detectlanguage();
    
    	if($language=="pt-BR"){
    	echo "Brasileiro no peito.";}
    
    	if($language=="fr-FR"){
    	echo "Bonjour French people.";}
    
    	if($language=="it-IT"){
    	echo "Ciao bella.";}
    
    	if($language=="es-ES"){
    	echo "Hola mi amor";}
    ?>

    It seems obvious, and I’m eager to learn if pointed towards good tut, but I’m no php master. Help please : )

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to add a Language detection hint?’ is closed to new replies.