Multilanguage website

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bettina@coaster.ch

    Multilanguage website

    My default language is german. It will be so defined in the main site:

    main.php
    <?
    $lang = 'ge';
    include("set_la nguage.php");
    ?>

    st_language.php
    <?php
    if (isset($_GET['lang']))
    {
    $lang = $_GET['lang'];
    }
    require("lang.{ $lang}.inc.php" );
    ?>
    <td align="left" width="50"><a href="?lang=ge" ><? echo "DEUTSCH"
    ?></a></td>
    <td align="left" width="50"><a href="?lang=en" ><? echo "ENGLISH"
    ?></a></td>
    <td align="left" width="50"><a href="?lang=sp" ><? echo "ESPAÑOL"
    ?></a></td>

    If I call another page it works pretty fine:
    .....
    <td><a href="breweries .php?lang=<? echo $lang ?>&code=<? echo
    $countries[$x][0] ?>"><? echo $countries[$x][1] ?></a></td>

    The problem is that, when I want to come back from breweries.php, I get
    main.php again in german and that's so because I set at the beginning
    $lang as 'ge'. But if I don't do that, I get an error. Is there a way
    to define the default value of this variable outside the programm?

    Note: I'm quite new in PHP.

    Thank you! Bettina

  • Jerry Stuckle

    #2
    Re: Multilanguage website

    bettina@coaster .ch wrote:[color=blue]
    > My default language is german. It will be so defined in the main site:
    >
    > main.php
    > <?
    > $lang = 'ge';
    > include("set_la nguage.php");
    > ?>
    >
    > st_language.php
    > <?php
    > if (isset($_GET['lang']))
    > {
    > $lang = $_GET['lang'];
    > }
    > require("lang.{ $lang}.inc.php" );
    > ?>
    > <td align="left" width="50"><a href="?lang=ge" ><? echo "DEUTSCH"
    > ?></a></td>
    > <td align="left" width="50"><a href="?lang=en" ><? echo "ENGLISH"
    > ?></a></td>
    > <td align="left" width="50"><a href="?lang=sp" ><? echo "ESPAÑOL"
    > ?></a></td>
    >
    > If I call another page it works pretty fine:
    > ....
    > <td><a href="breweries .php?lang=<? echo $lang ?>&code=<? echo
    > $countries[$x][0] ?>"><? echo $countries[$x][1] ?></a></td>
    >
    > The problem is that, when I want to come back from breweries.php, I get
    > main.php again in german and that's so because I set at the beginning
    > $lang as 'ge'. But if I don't do that, I get an error. Is there a way
    > to define the default value of this variable outside the programm?
    >
    > Note: I'm quite new in PHP.
    >
    > Thank you! Bettina
    >[/color]

    Maybe instead of using get variables, you could use session variables. If the
    session variable isn't set, set it to "ge". Otherwise use it.

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • petermichaux@yahoo.com

      #3
      Re: Multilanguage website

      I am doing exactly what Jerry suggested

      in "index.php" I have something like the following. (this isn't tested
      because really I have it spread out through a few files.)

      <?php

      session_start() ;

      define("DEFAULT _LANGUAGE", 'ge');
      define("SITE_RO OT", dirname(__FILE_ _));

      if ( !isset($_SESSIO N['Language']) )
      {
      $_SESSION['Language'] = DEFAULT_LANGUAG E;
      }
      require_once(SI TE_ROOT."/languages/".$_SESSION['Language']."/language.php");

      ?>

      Comment

      • bettina@coaster.ch

        #4
        Re: Multilanguage website

        I tried it but it doesn' t work.

        I wrote the following:

        main.php
        <?php
        session_start() ;
        define("DEFAULT _LANGUAGE", 'ge');
        define("SITE_RO OT", dirname(__FILE_ _));
        if (!isset($_SESSI ON['lang'])) {
        $_SESSION['lang'] = DEFAULT_LANGUAG E;
        }
        require_once(SI TE_ROOT."/set_language.ph p");
        ?>
        set_language.ph p
        <td align="left" width="50"><a href="main.php? lang=ge"><? echo
        "DEUTSCH" ?></a></td>
        <td align="left" width="50"><a href="main.php? lang=en"><? echo
        "ENGLISH" ?></a></td>
        <td align="left" width="50"><a href="main.php? lang=sp"><? echo
        "ESPAÑOL" ?></a></td>

        But now it doesn't even change the language at the start site. I would
        like that if one select english, for example, goes to different
        "sub-pages" in english and when coming back to main.php, the language
        is still English. How can I do?

        What is defined by define("SITE_RO OT", dirname(__FILE_ _));

        Thanks.
        Bettina

        Comment

        • bettina@coaster.ch

          #5
          Re: Multilanguage website

          Forget it. IT WORKS!

          Comment

          • Jerry Stuckle

            #6
            Re: Multilanguage website

            petermichaux@ya hoo.com wrote:[color=blue]
            > I am doing exactly what Jerry suggested
            >
            > in "index.php" I have something like the following. (this isn't tested
            > because really I have it spread out through a few files.)
            >
            > <?php
            >
            > session_start() ;
            >
            > define("DEFAULT _LANGUAGE", 'ge');
            > define("SITE_RO OT", dirname(__FILE_ _));
            >
            > if ( !isset($_SESSIO N['Language']) )
            > {
            > $_SESSION['Language'] = DEFAULT_LANGUAG E;
            > }
            > require_once(SI TE_ROOT."/languages/".$_SESSION['Language']."/language.php");
            >
            > ?>
            >[/color]

            Why confuse things with SITE_ROOT? If you want the server's root directory,
            $_SERVER['DOCUMENT_ROOT'] gives it to you.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            Working...