WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to add a Language detection hint? (4 posts)

  1. Aria
    Member
    Posted 2 years ago #

    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!

  2. 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.

  3. Aria
    Member
    Posted 2 years ago #

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

  4. Aria
    Member
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic