Multilangauge Website

Discussion in 'PHP' started by n3o, Feb 27, 2008.

  1. #1
    What is the Best way to create a multi-language website with SEO in mind ?

    i google search and found someone using this code



     [QUOTE]$langs = array('fr','en');
    session_start();
    if(isset($_GET['l']) && in_array($_GET['l'], $langs)) {
    $_SESSION['lang'] = $_GET['l'];
    } else {
    $_SESSION['lang'] = 'en';
    }
    header("Location: http://www.example.com/lang/index.".$_SESSION['lang'].".php");
    exit;
    
    Now the links on your page would be something along these lines:
    
    <a href="index.php?l=fr">French</a>
    <a href="index.php?l=en">English</a> [/QUOTE]
    PHP:

    wonder how i can apply to my site ...

    Hope someone can enlight me

    Thank You
     
    n3o, Feb 27, 2008 IP
  2. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    use redirect

    e.g. edit your htaccess file
     
    vonvhen, Feb 27, 2008 IP
  3. blacknet

    blacknet Active Member

    Messages:
    709
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    70
    #3
    try using babelfish :)
     
    blacknet, Feb 27, 2008 IP
  4. n3o

    n3o Well-Known Member

    Messages:
    1,241
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    160
    #4
    babelfish wont work ... it translate everything even my codes inside the form ..

    wanna do it manually and get ranked in foreign language also
     
    n3o, Feb 27, 2008 IP
  5. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    one way to do it is to get your contents inside a database and write a page to crawl it. then call the google translate page with the url of the page for the translation. you can save the translation back to your tables in your database.
     
    vonvhen, Feb 28, 2008 IP
  6. n3o

    n3o Well-Known Member

    Messages:
    1,241
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    160
    #6
    i dont want to use database ...

    i'm thinking this one is what i'm looking for ... but i dont really know how to use it ...

    do i have to use .htaccess redirect ? i want my visitor to have the ability to choose on it's own ..

    thanks in advance to people who reply

    <?php
    /**
    * index.php
    * multilingual website
    *  lang/index.fr.php    French translation
    *  lang/index.en.php    English translation
    *
    * @author Hatem <hatem@php.net>
    * @version 1.1.0    27 février 2002
    */
    
    /**
    * Detect and include language
    */
    session_start();
    
    if(!isset($lang)) {
        $lang = getenv('HTTP_ACCEPT_LANGUAGE');
        $lang_default = "en";
    }
    
    if (is_file("lang/index.$lang.php"))
    {
        $_SESSION["lang"] = $lang;
        include("lang/index.$lang.php");
    } else {
        $_SESSION["lang"] = $lang_default;
        include("lang/index.$lang_default.php");
    }
    
    
    /**
    * Then code your website here
    */
    echo _HELLO_;
    
    echo "\n"._INFO_;
    ?>
    
    
    
    <?php
    /**
    * lang/index.en.php
    */
    define("_HELLO_", "Hello");
    define("_INFO_", "This web site support english and french");
    ?>
    
    
    <?php
    /**
    * lang/index.fr.php
    */
    define("_HELLO_", "Salut");
    define("_INFO_", "Ce site web supporte l'anglais et le français");
    ?>
    PHP:
     
    n3o, Mar 1, 2008 IP
  7. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    No you don't need a redirect on your example. You just need to pass and capture the '$lang' variable from the page where the user choose from.

    e.g. <a href="yourlink?lang=en"></a>

    Also change the

    if(!isset($lang)) {

    to something like

    if(!isset($_GET['lang'])) { <--- this will capture the 'lang' variable from the url link.

    On you example, it is displaying a different page depending on their browser language.
     
    vonvhen, Mar 1, 2008 IP
  8. roy.laurie

    roy.laurie Peon

    Messages:
    51
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yup. I recommend using gettext for the actual multi-language part. Actually, I'd recommend doing it anyway just to separate content from code. So instead of having:

    echo 'This is my text.';
    PHP:
    You'd have:

    echo _('This is my text.');
    PHP:
    Not much more work, but a lot of benefits further down the road.
     
    roy.laurie, Mar 1, 2008 IP
  9. n3o

    n3o Well-Known Member

    Messages:
    1,241
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    160
    #9
    hi ... vonvhen and roy.laurie .. thanks for the reply ...

    i like the idea you both gave ... but since i dont have much php programming knowledge .. i dont know how i can apply these codes to my site :-S
     
    n3o, Mar 1, 2008 IP
  10. Panzer

    Panzer Active Member

    Messages:
    381
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    58
    #10
    Store user language in the database, use language strings.
     
    Panzer, Mar 1, 2008 IP
  11. vonvhen

    vonvhen Peon

    Messages:
    152
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Unless you learn some basic programming skill, your best way would be to use HTML and static pages.

    just name your pages with a different name and link to it on your main page.
     
    vonvhen, Mar 1, 2008 IP