+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 10 of 12

Thread: [TUTORIAL] Multi-Language WebSites

  1. #1
    x10 Elder DarkDragonLord is an unknown quantity at this point DarkDragonLord's Avatar
    Join Date
    Mar 2007
    Location
    Brazil
    Posts
    782

    Thumbs up [TUTORIAL] Multi-Language WebSites

    Greetings guys!

    Finally i could manage to find a great script that supports Multi-language websites WITHOUT databases :D
    As always, no english tutorial could help me and never worked. So i've searched in my home language and gotcha, i found :P

    Very nice for small / mid website but might be a little hard to manage in Big websites.

    It uses only 1 + 1*x files (where X is the number of languages you want) then, 2 languages are 3 files.

    Credits goes to user Cerrito (MRS) from " iMasters Fóruns " ( http://forum.imasters.com.br/index.php?showtopic=124045 ) that created the code
    And zé_violeiro ( http://forum.imasters.com.br/index.php?showtopic=224115 ) that changed code to make it work with images instead of a Drop Down Menu.


    I've translated most of the comments xD

    Ok, Lets start!

    First, create a file named setlanguage.php
    PHP Code:
    <?php
    /*** BY MRS 05/06/2004 ****\
    * *** *
    *  this file check if the user choosed a language. If true, it changes and saves a cookie for that setting  *
    * with a 1month duration, so next time it comes, already is in the language he previously set.  * 
    * if false, it check for a language cookie, if dont have, it get the browsers idiom and set as it *
    * +++ *
    /******************************************************** */

     
    $texto['portuguese']          = "Portugues";
     
    $texto['english']          = "English";
     
    $texto['spanish']          = "Espanol";

    // here you add the languages.

    ob_start();
    $default "en"// default will be english...

    if( isset( $_GET['lang'] ) )
    {
    require 
    $_GET['lang'] . ".php";
    setcookie("saveLang"$_GET['lang'], time()+3600*24*30'/'); // cookie that will expire in 1 month
    }
    else
    if( isset(
    $_COOKIE["saveLang"]) )
    {
    require 
    $_COOKIE["saveLang"] . ".php";
    }
    else
    if (!isset(
    $_SERVER['HTTP_ACCEPT_LANGUAGE']))
    {
    require 
    $default .".php";
    }
    else
    {
    $language $_SERVER['HTTP_ACCEPT_LANGUAGE'];
    $language substr($language,0,2); // splitting languages....
    if( ( $language == "pt") or ( $language == "es") or ( $language == "en") ) // checking if language is valid .. here you can change or add the languages
    {
    require 
    $language".php";
    }
    else
    {
    require 
    $default ".php";
    }
    }
    ob_end_flush();
    ?>

    Now, to the language files!
    en.php or es.php or pt.php or anything .php.. Just remember of making sure to add it at setlanguage.php where check the language if valid.

    pt.php
    PHP Code:
    <?
        $texto
    ['titulo']               =   "Informações do sistema";
        
    $texto['usada']                =   "Usado";
        
    $texto['livre']                =   "Livre";
        
    $texto['espacoTotal']          =   "Tamanho";
        
    $texto['dataHora']             =   "Data/Hora";
        
    $texto['nomeDaMaquina']        =   "None do servidor";
        
    $texto['dominio']              =   "Dominio";
        
    $texto['host']                 =   "Host";
        
    $texto['uptime']               =   "Tempo de vida";
        
    $texto['numeroProcessos']      =   "Numero de Processos";
        
    $texto['sistemaOperacional']   =   "Sistema operacional";
        
    $texto['vKernel']              =   "Versão do Kernel";
        
    $texto['usuarios']             =   "Usuários";
    ?>
    And en.php
    PHP Code:
    <?php
    $texto
    ['titulo']               = "System Information";
    $texto['usada']                = "Usage";
    $texto['livre']                = "Free";
    $texto['espacoTotal']          = "Space total";
    $texto['dataHora']             = "Date/time";
    $texto['nomeDaMaquina']        = "Computer Name";
    $texto['dominio']              = "Domain";
    $texto['host']                 = "Host address";
    $texto['uptime']               = "Server time life";
    $texto['numeroProcessos']      = "Processors number";
    $texto['sistemaOperacional']   = "Operational System";
    $texto['vKernel']              = "Kernel Version";
    $texto['usuarios']             = "Users";

    ?>

    explanation:
    $texto['VARIABLE_YOU_WANT'] = "The meaning of the variable";

    a better example:
    You want to have all your Menu links to be language changeable.
    so you make:

    PHP Code:
    FOR EN.PHP

    <?php
    $texto
    ['home']               = "Home";
    $texto['downloads']                = "Downloads";
    $texto['support']                = "Support";
    $texto['contact']          = "Contact";
    ?>

    FOR PT.PHP

    <?php
     $texto
    ['home']               = "Página Inicial";
     
    $texto['downloads']                = "Downloads";
     
    $texto['support']                = "Suporte";
     
    $texto['contact']          = "Contato";
    ?>
    simple isn't it? always make the variable inside [' '] same in every languages

    Ok, next step.


    In the index.php (or the page you want) add at beggining:

    PHP Code:
    <?php
    include "setlanguage.php";
    ?>
    For the Change Language Links / Images is this:
    HTML Code:
    <a href="<?php $_SERVER['PHP_SELF'] ?>?lang=pt"><?php echo $texto['portuguese']; ?></a>
    
    <a href="<?php $_SERVER['PHP_SELF'] ?>?lang=en"><?php echo $texto['english']; ?></a>
    the $_SERVER is to make the php get itself, this way you dont need to write the php file name all time (so if you want to rename it later, you'll have to change in the links) and the php and echo is used with those arrays you set up at beggining of setlanguage.php. If you want a image instead of a name, just put

    HTML Code:
    <a href="<?php $_SERVER['PHP_SELF'] ?>?lang=en"><img src="IMAGE" border="0"></a>
    With all set up, now lets add our variables at where you want.



    a common menu:
    HTML Code:
    <a href="<?php $_SERVER['PHP_SELF'] ?>?id=home">HOME</a> <br />
    <a href="<?php $_SERVER['PHP_SELF'] ?>?id=downloads">DOWNLOADS</a> <br />
    <a href="<?php $_SERVER['PHP_SELF'] ?>?id=support">SUPPORT</a> <br />
    <a href="<?php $_SERVER['PHP_SELF'] ?>?id=contact">CONTACT</a> <br />
    Now, the new menu that will change the names if changed language:
    HTML Code:
    <a href="<?php $_SERVER['PHP_SELF'] ?>?id=home"><?php echo $texto['home']; ?></a> <br />
    <a href="<?php $_SERVER['PHP_SELF'] ?>?id=downloads"><?php echo $texto['downloads']; ?></a> <br />
    <a href="<?php $_SERVER['PHP_SELF'] ?>?id=support"><?php echo $texto['support']; ?></a> <br />
    <a href="<?php $_SERVER['PHP_SELF'] ?>?id=contact"><?php echo $texto['contact']; ?></a> <br />
    Its done!
    When you change the languages, the menu automatically changes the names ^^


    I think this could be made with all texts too but you will have to write each text twice, one in english one in the other language then add the <?php echo $texto['VARIABLE']; ?>


    I hope this help most of people to make a Multi-language website.

    I know, i could charge everyone to make it work for you but i think its better this way. (but i still can do for you if you are lazy enough for some credits :D)


    see you ^^



    If you think this tutorial post was helpful, click in the reputation button in the beginning of this post, in the right side ( ).
    And if you think it worth something i translated and shared it with you, i would be grateful if you donate some credits ^^
    Last edited by DarkDragonLord; 11-09-2007 at 12:23 PM.
    Regards,
    Raphael DDL

    Designing Solutions for You
    *Web Design;
    *Coding;
    Free Downloads;
    and all related Stuff
    .


    My Tutorials:
    | Multi-Language Websites | Rotative Banners |
    | Bookmark Script for All Browsers
    |
    |
    PHP Switching/Including Content|
    |


  2. #2
    Lord Of The Keys Slothie is an unknown quantity at this point Slothie's Avatar
    Join Date
    Sep 2007
    Location
    Singapore
    Posts
    1,432

    Re: [TUTORIAL] Multi-Language WebSites

    I prefer using getText for localization in most of my apps but yeah, nice tutorial.

    Easiest 70 points you'll make on x10

    Feel free to add my reputation by clicking on the if you found my post helpful to you :P


    If I am not responding to your PMs, that means I am ignoring you. Take a hint.



    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0


  3. #3
    x10Hosting Member ikarus is an unknown quantity at this point
    Join Date
    Oct 2007
    Posts
    1

    Re: [TUTORIAL] Multi-Language WebSites

    thank you

  4. #4
    x10 Lieutenant eminemix is an unknown quantity at this point eminemix's Avatar
    Join Date
    Sep 2007
    Location
    EU
    Posts
    348

    Re: [TUTORIAL] Multi-Language WebSites

    Thanks.


  5. #5
    x10 Elder DarkDragonLord is an unknown quantity at this point DarkDragonLord's Avatar
    Join Date
    Mar 2007
    Location
    Brazil
    Posts
    782

    Re: [TUTORIAL] Multi-Language WebSites

    Tomorrow i'll make an Add-on tutorial of this one showing how use this variables for images, and how make them detect the browser's language using part of the setlanguage.php code.
    Regards,
    Raphael DDL

    Designing Solutions for You
    *Web Design;
    *Coding;
    Free Downloads;
    and all related Stuff
    .


    My Tutorials:
    | Multi-Language Websites | Rotative Banners |
    | Bookmark Script for All Browsers
    |
    |
    PHP Switching/Including Content|
    |


  6. #6
    x10Hosting Member cool_dude_99 is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    23

    Re: [TUTORIAL] Multi-Language WebSites

    Nice ..Thanks

  7. #7
    Lord Of The Keys LHVWB is an unknown quantity at this point LHVWB's Avatar
    Join Date
    Jan 2008
    Location
    Australia
    Posts
    1,308

    Re: [TUTORIAL] Multi-Language WebSites

    Nice system.
    I use the inbuilt system with SFM to do my language support,it automatically allows you to select languages, and I have a language bar for the user to change the language. It has a very similar system where you can change and add text to the $txt array in different files for different languages.

    The easiest option for multi-language support is probably to integrate your site with a user system that already has the language, but you system's nice because it doesn't need the user system.

  8. #8
    x10 Spammer tittat is an unknown quantity at this point tittat's Avatar
    Join Date
    Sep 2007
    Location
    Kerala,India
    Posts
    2,480

    Re: [TUTORIAL] Multi-Language WebSites

    any way nice tutorial.But i didn't tried to setup script now.will do later.*******repped*******
    Last edited by tittat; 03-29-2008 at 10:15 PM.

  9. #9
    x10 Sophmore ThePaintGuru is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    208

    Re: [TUTORIAL] Multi-Language WebSites

    This is a very helpful (and timely) tutorial for me, I'm just in the process of coding a new website in English and Spanish. Will have to work on my translation skills, though .
    ----------
    If you found my post helpful in some way, I'd really appreciate a few credits as I'm saving up for a domain.

    You can click the blue check mark in the upper right corner of this post to increase my reputation.

  10. #10
    Lord Of The Keys LHVWB is an unknown quantity at this point LHVWB's Avatar
    Join Date
    Jan 2008
    Location
    Australia
    Posts
    1,308

    Re: [TUTORIAL] Multi-Language WebSites

    Here is an easy tutorial for doing a similar thing but with the built in SMF system, if anyone is interested.

    http://verbsite.x10hosting.com/index...=mod_languages

+ Reply to Thread
Page 1 of 2
1 2 LastLast

Similar Threads

  1. Any good PHP websites?
    By soten355 in forum Scripts & 3rd Party Apps
    Replies: 10
    Last Post: 01-29-2009, 09:47 AM
  2. Web language
    By Marzy in forum Feedback and Suggestions
    Replies: 9
    Last Post: 11-07-2007, 08:09 PM
  3. site language...
    By ymca in forum Free Hosting
    Replies: 6
    Last Post: 11-10-2005, 10:26 AM
  4. Relax Language Requirements
    By Wai_Wai in forum Feedback and Suggestions
    Replies: 22
    Last Post: 09-16-2005, 04:41 PM

Posting Permissions

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