Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: multi-language site + slideshow

  1. #1
    Join Date
    Apr 2010
    Posts
    40
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default multi-language site + slideshow

    Hi, i'm constructing a multi-language site. in the top of the page there are links to change the language. by using echo
    eg:
    PHP Code:
    <title><?php echo $lang['PAGE_TITLE'];?></title>
    the variables send to a php (say common.php) file. then this php file calls another 3 php files (say lang.en.php, lang.de.php & lang.es.php) which contain the content of different 3 languages.
    eg:in lang.en.php
    PHP Code:
    $lang['PAGE_TITLE'] = 'Testing Page'
    there is no issue with changing the content.

    but there is a slideshow. for different 3 languages there should be different slideshow images.
    since in this site there is no database it was hard to me.
    if you can tell me how can i call the common.php and how the define the path to different images in lang.en.php, lang.de.php & lang.es.php , it would be grate help. hope you can understand my problem. all replies are very welcome.
    thank you.
    Last edited by madu; 12-24-2010 at 09:45 AM.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Can you post the code you have for populating the slideshow images?

    It would be good to see how the files are laid out and when you're calling them on the page.

    You want to create arrays depending on the language the user's chosen, and then in the language files, have something like:

    lang.es.php:
    PHP Code:
    $lang['slideshow'] = array('imagen1.jpg''imagen2.jpg'); 
    lang.en.php:
    PHP Code:
    $lang['slideshow'] = array('image1.jpg''image2.jpg'); 
    common.php:
    PHP Code:
    foreach($lang['slideshow'] as $image) {
        echo 
    '<img src="' $image '" alt="' $image '" />';

    I realise that the HTML above isn't what you'd be using for the slideshow, but the principle is the same. Whether you need to populate a JavaScript array or anything similar, you can just loop through that slideshow array and pull out the values you need.

    Depending on how your script's currently set up though, the above code may need altering, but if you can post the code it will be easier to see what needs to be done.

  3. The Following User Says Thank You to Schmoopy For This Useful Post:

    madu (12-24-2010)

  4. #3
    Join Date
    Apr 2010
    Posts
    40
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    thanx for reply me....

    this is the slide show,
    Code:
    <div class="rap"> 
    <img src="extra/slide1.jpg" width="860" height="270" /> 
    <img src="extra/slide2.jpg" width="860" height="270" /> 
    <img src="extra/slide3.jpg" width="860" height="270" /> 
    <img src="extra/slide4.jpg" width="860" height="270" /> 
    </div>
    this is the common.php
    PHP Code:
    session_start();
    header('Cache-control: private'); // IE 6 FIX

    if(isSet($_GET['lang']))
    {
    $lang $_GET['lang'];

    // register the session and set the cookie
    $_SESSION['lang'] = $lang;

    setcookie("lang"$langtime() + (3600 24 30));
    }
    else if(isSet(
    $_SESSION['lang']))
    {
    $lang $_SESSION['lang'];
    }
    else if(isSet(
    $_COOKIE['lang']))
    {
    $lang $_COOKIE['lang'];
    }
    else
    {
    $lang 'en';
    }

    switch (
    $lang) {
      case 
    'en':
      
    $lang_file 'lang.en.php';
      break;

      case 
    'sin':
      
    $lang_file 'lang.de.php';
      break;

      case 
    'tam':
      
    $lang_file 'lang.es.php';
      break;

      default:
      
    $lang_file 'lang.en.php';

    }

    include_once 
    'languages/'.$lang_file
    i have, what are the language files in the common.php.

    and this is the lang.en.php
    PHP Code:
    <?php
    /* 
    ------------------
    Language: English
    ------------------
    */

    $lang = array();

    $lang['PAGE_TITLE'] = 'Testing Page';

    // Menu

    $lang['Menu_Home'] = 'Home';

    .......................
    ................................
    hope now you have clear idea. please help me...
    tahnk you very much

  5. #4
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Change your language files to look like:

    lang.en.php
    PHP Code:
    <?php
    /* 
    ------------------
    Language: English
    ------------------
    */

    // Define the images you want for this language in the array below
    $images = array('slide1.jpg''slide2.jpg''slide3.jpg''slide4.jpg');

    $lang = array();

    $lang['PAGE_TITLE'] = 'Testing Page';

    // Menu

    $lang['Menu_Home'] = 'Home';

    $lang['slideshow'] = $images;
    ?>
    Replace the current HTML you have for outputting the slideshow with:

    PHP Code:
    <div class="rap">
    <?php
    foreach($lang['slideshow'] as $image) {
    ?>
    <img src="extra/<?php echo $image?>" width="860" height="270" /> 
    <?php
    }
    ?>
    </div>
    You don't need to make any changes to common.php for this to work.
    Obviously you need to change the $images variable in each of your language files with whatever images you want.

    Good luck!
    Last edited by Schmoopy; 12-24-2010 at 08:31 PM.

  6. #5
    Join Date
    Apr 2010
    Posts
    40
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    thank you Schmoopy. but still there is something in the code.
    when i change these modifications there is an error called ": Invalid argument supplied for foreach() in C:\wamp\www\Test\index.php on line "
    then i change the code
    Code:
    <div class="rap">
    <?php
    foreach($lang as $image) {
    ?>
    <img src="extra/<?php echo $image['slideshow']; ?>" width="860" height="270" /> 
    <?php
    }
    ?>
    </div>
    then there is no error and no out put also.

    the lang.en.php placed in folder called language. and images are placed in folder called images.
    then this the ang.en.php
    PHP Code:
    <?php
    /* 
    ------------------
    Language: English
    ------------------
    */


    // Define the images you want for this language in the array below
    $images = array('../images/slide1.jpg''../images/slide2.jpg''../images/slide1.jpg''../images/slide2.jpg');

    $lang = array();

    // slideshow
    $lang['slideshow'] = $images;

    $lang['PAGE_TITLE'] = 'Testing Page';

    // Menu

    $lang['Menu_Home'] = 'Home';
    $lang['Menu_About_us'] = 'About Us'
    ..............
    ....................
    but still no image shown in index page. what has happened to this code. what is the error? your help much needed.
    thanx a lot.

  7. #6
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Ok here's how it should look. Your foreach statement should be looping through $lang['slideshow'], not just $lang.

    Here's a version that combines all the code into one file, so you can see how it should flow:
    PHP Code:
    <?php
    // START COMMON.PHP

    session_start();
    header('Cache-control: private'); // IE 6 FIX

    if(isSet($_GET['lang']))
    {
    $lang $_GET['lang'];

    // register the session and set the cookie
    $_SESSION['lang'] = $lang;

    setcookie("lang"$langtime() + (3600 24 30));
    }
    else if(isSet(
    $_SESSION['lang']))
    {
    $lang $_SESSION['lang'];
    }
    else if(isSet(
    $_COOKIE['lang']))
    {
    $lang $_COOKIE['lang'];
    }
    else
    {
    $lang 'en';
    }

    switch (
    $lang) {
      case 
    'en':
      
    $lang_file 'lang.en.php';
      break;

      case 
    'sin':
      
    $lang_file 'lang.de.php';
      break;

      case 
    'tam':
      
    $lang_file 'lang.es.php';
      break;

      default:
      
    $lang_file 'lang.en.php';

    }
    // Commented out the line below because we don't need the include, hard coded in below
    //include_once 'languages/'.$lang_file;

    // START LANG.EN.PHP

    /* 
    ------------------
    Language: English
    ------------------
    */

    // Define the images you want for this language in the array below
    $images = array('slide1.jpg''slide2.jpg''slide3.jpg''slide4.jpg');

    $lang = array();

    $lang['PAGE_TITLE'] = 'Testing Page';

    // Menu

    $lang['Menu_Home'] = 'Home';

    $lang['slideshow'] = $images;

    // END LANG.EN.PHP

    // START COMMON.PHP
    ?>
    <div class="rap">
    <?php
    foreach($lang['slideshow'] as $image) {
    ?>
    <img src="extra/<?php echo $image?>" width="860" height="270" /> 
    <?php
    }
    ?>
    </div>

    <?php
    // END COMMON.PHP
    ?>
    I have this running on my local server and it outputs:

    Code:
    <div class="rap">
    <img src="extra/slide1.jpg" width="860" height="270" /> 
    <img src="extra/slide2.jpg" width="860" height="270" /> 
    <img src="extra/slide3.jpg" width="860" height="270" /> 
    <img src="extra/slide4.jpg" width="860" height="270" /> 
    </div>
    Let me know when you get this running.

  8. The Following User Says Thank You to Schmoopy For This Useful Post:

    madu (12-25-2010)

  9. #7
    Join Date
    Apr 2010
    Posts
    40
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    YES! it's working!!! thank you.....
    when combining common.php & lang.en.php like your last post, it was showing 2 slide shows. then i remove
    PHP Code:
    <div class="rap">
    <?php
    foreach($lang['slideshow'] as $image) {
    ?>
    <img src="extra/<?php echo $image?>" width="860" height="270" /> 
    <?php
    }
    ?>
    </div>
    from your new combine code. after it was working.

    but combining common.php & lang.en.php, how to define lang.de.php & lang.es.php for other 2 languages ???


    if we can use again
    PHP Code:
    include_once 'languages/'.$lang_file
    and use difference 3 php files for 3 languages it would be fine and nice.

    please help me Schmoopy. thnx again for your kindly help.

  10. #8
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    To get it working for all 3 files, and additional language files if needed, do the following:


    common.php:

    PHP Code:
    <?php
    session_start
    ();
    header('Cache-control: private'); // IE 6 FIX

    if(isSet($_GET['lang']))
    {
    $lang $_GET['lang'];

    // register the session and set the cookie
    $_SESSION['lang'] = $lang;

    setcookie("lang"$langtime() + (3600 24 30));
    }
    else if(isSet(
    $_SESSION['lang']))
    {
    $lang $_SESSION['lang'];
    }
    else if(isSet(
    $_COOKIE['lang']))
    {
    $lang $_COOKIE['lang'];
    }
    else
    {
    $lang 'en';
    }

    switch (
    $lang) {
      case 
    'en':
      
    $lang_file 'lang.en.php';
      break;

      case 
    'sin':
      
    $lang_file 'lang.de.php';
      break;

      case 
    'tam':
      
    $lang_file 'lang.es.php';
      break;

      default:
      
    $lang_file 'lang.en.php';

    }

    include_once 
    'languages/'.$lang_file;
    ?>
    <div class="rap">
    <?php
    foreach($lang['slideshow'] as $image) {
    ?>
    <img src="extra/<?php echo $image?>" width="860" height="270" /> 
    <?php
    }
    ?>
    </div>
    lang.en.php:

    PHP Code:
    <?php
    /* 
    ------------------
    Language: English
    ------------------
    */


    // Define the images you want for this language in the array below
    $images = array('../images/slide1.jpg''../images/slide2.jpg''../images/slide1.jpg''../images/slide2.jpg');

    $lang = array();

    // slideshow
    $lang['slideshow'] = $images;

    $lang['PAGE_TITLE'] = 'Testing Page';

    // Menu

    $lang['Menu_Home'] = 'Home';
    $lang['Menu_About_us'] = 'About Us';

    ?>
    lang.de.php:

    PHP Code:
    <?php
    /* 
    ------------------
    Language: Dutch
    ------------------
    */


    // Define the images you want for this language in the array below
    $images = array('../images/dutch1.jpg''../images/dutch2.jpg''../images/dutch3.jpg''../images/dutch4.jpg');

    $lang = array();

    // slideshow
    $lang['slideshow'] = $images;

    $lang['PAGE_TITLE'] = 'Danish Page';

    // Menu

    $lang['Menu_Home'] = 'Home'// (whatever "Home" is in Dutch)
    $lang['Menu_About_us'] = 'About Us'// (whatever "About Us" is in Dutch)

    ?>
    lang.es.php:

    PHP Code:
    <?php
    /* 
    ------------------
    Language: Spanish
    ------------------
    */


    // Define the images you want for this language in the array below
    $images = array('../images/diapositiva1.jpg''../images/diapositiva2.jpg''../images/diapositiva3.jpg''../images/diapositiva4.jpg');

    $lang = array();

    // slideshow
    $lang['slideshow'] = $images;

    $lang['PAGE_TITLE'] = 'Pagina de Prueba';

    // Menu

    $lang['Menu_Home'] = 'Inicio';
    $lang['Menu_About_us'] = 'Quiénes somos';

    ?>
    That should do it for you.

    Let me know how you get on.

  11. The Following User Says Thank You to Schmoopy For This Useful Post:

    madu (12-26-2010)

  12. #9
    Join Date
    Apr 2010
    Posts
    40
    Thanks
    13
    Thanked 0 Times in 0 Posts

    Default

    YES! YES!! YES!!! it's working. thank you Schmoopy. thank you very much.

  13. #10
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Glad it worked for you.

    Good luck with your site!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •