WordPress.org

Ready to get started?Download WordPress

Forums

redirect using HTTP_ACCEPT_LANGUAGE (3 posts)

  1. Kalebeul
    Member
    Posted 7 years ago #

    I'm trying to read / set http_accept_language to:
    1) give users text in their browser default language;
    2) give them the option of changing to another language.
    My code works fine:
    http://oreneta.com/kalebeul/test.php
    but dies once it goes into a WordPress template (same code/text near bottom right-hand column):
    http://oreneta.com/kalebeul/2006/10/13/2000-catalan-insults/
    Here's my code:
    <?php
    $day=(date('d'));
    $month=(date('m'));
    if ($userlang=="")
    {
    $userlang=$_SERVER['HTTP_ACCEPT_LANGUAGE'];
    $userlang=substr($userlang,0,2);
    }
    if ($userlang=="es")
    {
    include("http://oreneta.com/libro_verde_bcn/es/$month/$day/");
    echo "(<small><a href="?userlang=en">Traducción</a>)</small>";
    }
    else
    {
    include("http://oreneta.com/libro_verde_bcn/en/$month/$day/");
    echo "(<small><a href="?userlang=es">Original</a>)</small>";
    }
    ?>

    Any ideas? I thought at first it was a register globals thing, but not sure now.

  2. lxg
    Member
    Posted 7 years ago #

    Before you reinvent the wheel: Check the Polyglot plugin:
    http://www.fredfred.net/skriker/index.php/polyglot

  3. Kalebeul
    Member
    Posted 7 years ago #

    Yeah, I use that somewhere else. Do you know by any chance if it comes up against and deals with this issue?

Topic Closed

This topic has been closed to new replies.

About this Topic