language file in php ?

Discussion in 'PHP' started by myharshdesigner, Sep 27, 2007.

  1. #1
    how can i make multi - language file for my website in php ?
     
    myharshdesigner, Sep 27, 2007 IP
  2. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #2
    There are differents methods but basicly you have let's say (X) folders where X is the number of languages:
    In my example I have 2 languages : french and english

    these folders will contain the files an images for each language (the same file names but different content).

    Example files:

    ./languages/english/main.php
    // 
    $_NAVIGATION_=array(
    	'site_name'=>'Free classifieds',
    	'home'=>'Home',
    	'country'=>'Country',
    	'time_format'=>'%m/%d/%Y',
    	'read_more'=>'... read more',
    	'footer'=>'©2007 example.com - All rughts bla bla',
    	);
    PHP:
    ./languages/french/main.php
    
    // 
    $_NAVIGATION_=array(
    	'site_name'=>'Annonces gratuites',
    	'home'=>'Accueil',
    	'country'=>'Pays',
    	'time_format'=>'%d/%m/%Y',
    	'read_more'=>'... poursuivre la lecture',
    	'footer'=>'©2007 example.com - Tous droits réservés',
    	);
    PHP:
    On your script you'll include the language file depending on the user choice/ stored cooky ...

    index.php
    
    $available_languages = array ('english','french'); 
    $default_language = 'english';
    $chosen_language = $default_language;
    
    if(in_array(cookie['language'],$available_languages)){
        $chosen_language = cookie['language'];
    }
    
    //Save the value of the chosen language on a cookie
    setcookie('language', $chosen_language, time()+60*60*24*30);
    
    //Now let's test it
    
    include ("./languages/$chosen_language/main.php");
    echo $_NAVIGATION_['site_name'];
    PHP:
    This example will show the site name depending on the chosen language.

    Of course you'll have to make a script that allows the user to change the language.

    You may also set the default language (when no coockie exists) to be the user's navigator language. (I'll show you if you want... very easy)
     
    nabil_kadimi, Sep 27, 2007 IP
    birdsq likes this.
  3. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks this script works for static data what about when we have dynamic data something like blogs ?




     
    myharshdesigner, Sep 27, 2007 IP
  4. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    and how to create file even you don't know the language ?
     
    myharshdesigner, Sep 27, 2007 IP
  5. krt

    krt Well-Known Member

    Messages:
    829
    Likes Received:
    38
    Best Answers:
    0
    Trophy Points:
    120
    #5
    That's optimistic... you expect to be able to create a multi language web site without doing any translating yourself.

    I guess you could try online translators such as Google language tools or pay someone to do it for you, or maybe allowing readers to translate and post on their own blog with a backlink.
     
    krt, Sep 27, 2007 IP
  6. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    ok then how to translate through Google language ?

    and thanks for your help :)

     
    myharshdesigner, Sep 27, 2007 IP
  7. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #7
    I can translate to french & arabic, I'm an experienced translator as well.

    You'll have to store the language on a database as well.. That how I did it on my arabix/english classifieds website.

    This is how it works : if someone ads a classified ad from the arabic form, the ad will be stored on the DB with a value of "ar" in the language column.

    and if someone else is viewing the arabic ads, he will only see the ads that have "ar" as a language on the database (this is done with sql queris).

    ...
     
    nabil_kadimi, Sep 27, 2007 IP
  8. myharshdesigner

    myharshdesigner Peon

    Messages:
    147
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    can you give some tutorial or code to translate languages ?

    Thanks for Devoting your time :)

     
    myharshdesigner, Sep 29, 2007 IP
  9. nabil_kadimi

    nabil_kadimi Well-Known Member

    Messages:
    1,065
    Likes Received:
    69
    Best Answers:
    0
    Trophy Points:
    195
    #9
    nabil_kadimi, Sep 29, 2007 IP
  10. n3o

    n3o Well-Known Member

    Messages:
    1,241
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    160
    #10

    this seems to be the perfect way of coding multi language site ... can you please show a complete tuts for that ... or point to one .. if there is any

    Thanks alot
     
    n3o, Feb 24, 2008 IP