SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2001
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    3 languages, 1 file, php? Long story :/

    Hi. If you look at my postcount, you'll see I'm as new as one can be . I have a little 'problem', and I was wondering if you guys could help me.

    First, I'll give a short version of the story:

    I want my visitors to choose from 3 languages for my entire site. They should make the choice once every time they visit the site. Then, every time they click a link (links are solid, can't be changed), the page the look at should be in the language they chose at the start of their visit.

    This isn't enough info, but it's a raw view of the story


    Onwards to the real story


    The site: http://www.rondvaartalkmaar.nl


    I have built a site for my boss, it's nothing special and I did it for free. Just because I think it's fun to do. I work for a company that arranges boattrips through our town, so the site should be in 3 languages. At the moment, it's still in just one language (which would be, erm, Dutch. I know, st00pid language ).
    It's a small site, with a small Flash menu system (made with Adobe Livemotion, some time ago). Due to a HD crash I lost the original file of the current .swf-menu, so I can't change the links anymore. And even if I could, it would only make the swf even larger than it is already, which is not quite acceptable. So the menu links to specific pages, and the links cannot be changed.

    What I want to do, is to offer my visitors the choice to view the site in their language (Dutch, German or English). When they click a link to go to, let's say, info.html, that page will have a frame containing info.php (stored on another server, with a mysql db). The info.php file will check what language the visitor wants, and show the correct language. I want to do this with every page on the site, because of the hd crash mentioned above.

    Since I'm a total newbee on php, and mysql databases, I completely in the dark on how to do this. I have a feeling it should be possible (especially when I look at to possibilities of 'difficult' software like vbulletin), but I haven't go a clue on how to make this. I'm anxious to learn new things, but I have to begin somewhere ey?

    If someone could help me a bit with this, I'd be extremely happy
    And I, of course, am innocent of all but malice

  2. #2
    SitePoint Zealot vodica's Avatar
    Join Date
    Jul 2001
    Location
    SLovenia
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, here is the deal! Throug what I undersand you wan't ONE single page (index.php) to have 3 languages? This can be made using sessions or cookies. Although every time a user visites your site he would have to choose the language!?

    So, when a user clicks the selected language you want to push it al the way through the page! If you are not already using SQL you don't need to!

    Does the page have to redirect you to another page due to the language or do you want one page that loads it's text from other files like eng.dat de.dat and dut.dat?

    Well, write write, write .... hehe



    Also:
    if you can't change the menu we can't help you you know?
    What do you expect a user to come, know DUTCH and then read english??

    I am fairly experienced at flash and can make you a menu similar to that if you want
    Last edited by vodica; Aug 11, 2001 at 12:55.
    while(true) sheep++;

  3. #3
    SitePoint Addict kunal's Avatar
    Join Date
    Oct 2000
    Posts
    307
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, the way most people do it, is that they have variables for each and every word on the page. example :

    for the english language they would use the file english.lang
    for the dutch langauage they would use the file dutch.lang


    now these files would have variables like :

    $welcome = "welcome to my page";
    $news = "news";


    etc etc...

    on the main page, they let the user select the language they wish. And store the variable in a cookie... that cookie is called for everytime the user visits the page, and accordingly the language file is called and the variables on the main page are replaced by the language specific variables.


    get an idea?
    i dunno...

  4. #4
    [Call me Bram] iBram007's Avatar
    Join Date
    Feb 2001
    Location
    Belgium
    Posts
    339
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I do it as follow:

    ENGLISH.PHP
    PHP Code:
    <?
    $lang 
    = array(
    0    => 'Todays active topics',
    1    => 'Your last visit',
    2    => 'The time is now',
    3    => 'Author',
    4    => 'Replies');
    ?>
    INDEX.PHP (first lines!)
    PHP Code:
    <?
    if(isset($lang) && $action=="set"){
    setcookie("lang",$lang);
    }
    if(empty(
    $lang)){ ?>
    <a href="?lang=english&action=set">English</a> - <a href="?lang=dutch&action=set">Dutch</a> - <a href="?lang=french&action=set">French</a>
    <? exit; }
    if(isset(
    $lang)){
    include(
    "$lang.php");
    }
    ?>

  5. #5
    The Hiding One lynlimz's Avatar
    Join Date
    Jul 2000
    Location
    Singapore
    Posts
    2,103
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I actually just did a script with multi-language support. While I haven't looked at any other script with multi-language support, its been working really fine for me.

    Its using PHP Classes and Object Orientation.

    Her'es the code.

    This is the function called at the top of any page that has multi-language support.
    PHP Code:
    function iniLang()
    {
        global 
    $setLang$HTTP_HOST$SERVER_NAME$SCRIPT_NAME$QUERY_STRING$path$cookieLang;
        if (
    $setLang) { $defaultLang = new selectLang($setLang); } // if $setLang, Change Language File to Variable
        
    elseif ($cookieLang) { $defaultLang = new selectLang($cookieLang); } // if cookie set
        
    else { $defaultLang = new selectLang(); }

        
    $defaultLang->existLang();
        if (!
    $cookieLang || $setLang) {
            if (
    $HTTP_HOST != $SERVER_NAME) { // If no 'WWW', Cookie won't work in Netscape
                
    header ("Location: [url]http://www.[/url]$HTTP_HOST$SCRIPT_NAME?$QUERY_STRING");
                exit;
            }
            
    setcookie ("cookieLang"$defaultLang->languagetime()+31536000"/"".$HTTP_HOST"0); // Sets a Cookie which will Expire in a Year's time
            
    $new_lang ucfirst($defaultLang->language);
            if (
    $defaultLang->declare) {
                
    $return 'Setting to Default Language [' $new_lang '] as Language Declared was Invalid.<br><br>';
            }
            else {
                
    $return $new_lang ' Language Selected Successfully.<br><br>';
            }
        }

        include(
    "$path/lang/$defaultLang->language.php");
        return 
    $return;

    This is the PHP Class file for assigning the requested language file.
    PHP Code:
    <?php

    // Language Class File
    // Copyright (c) 2001 Lyon Lim - For File Protocol 1.0

    $path '/home/lynlimz/public_html/miranda';

    class 
    selectLang // [Class : Main Language Class]
        
    var $language$declare// Declare Variables. $language = language selected, $declare = 1/0 if language exists

        
    function selectLang($language "english"// Function to Set Language
        
    {
            
    $this->language $language// Assign variable language to $defaultLang->language
        
    }
        function 
    existLang() // Function to Check if Language File Exists
        
    {
            global 
    $path;   // Variable for Path Location
            
    if (file_exists("$path/lang/$this->language.php")) { // Verifies if Language File exists
                
    $this->declare 0// Returns false if language exists
            
    }
            else {
                
    $this->language 'english'// Assign Default Language file, English if language declared void
                
    $this->declare 1// Returns false if language does not exist
            
    }
        }
    }

    ?>
    And finally, this is how a typical language file would look like.

    PHP Code:
    <?php

    /*
    Language Class File :: English
    Copyright (c) 2001 Lyon Lim - For File Protocol 1.0

    Explanation of Terms used - WHERE XX represents a corresponding number from the previous, starting from 1.
    - login_XX  Used in Access Class File


    Calling Methods [E.G.]
    - $Lang->login_XX
     
    */

    class getLang {

        function 
    getLang() {
            global 
    $system_name$url_path$file_index$file_login$ident;
            global 
    $user// for main_XX
            // login.php
            
    $this->login_1 'Login';
            
    $this->login_2 'Identification';
            
    $this->login_3 'Password';
            
    $this->login_4 'Identification and Password are Case-Sensitive.';
            
    $this->login_5 'Login Failed. This Account is';
            
    $this->login_6 'Suspended';
            
    $this->login_7 'Awaiting Approval';
            
    $this->login_8 'User not Authenticated Successfully. Please Try Again';
            
    $this->login_9 'Create New Account';
            
    $this->login_10 'Your Account has to be Approved by an Administrator before it becomes Active.';
            
    $this->login_11 'You only need an Account if you\'re uploading Files.';
            
    $this->login_12 $this->login_2 ' and ' $this->login_3 ' are Case-Sensitive.';
            
    $this->login_13 'For Security Reasons';
            
    $this->login_14 'Use a Unique Password consisting of Uppercase/Lowercase Letters and Numbers.';
            
    $this->login_15 'Please do not use your Valuable Passwords - Like those on SourceForge.';
            
    $this->login_16 'Verify ' $this->login_3;
            
    $this->login_17 'E-Mail';
            
    $this->login_18 $this->login_1 ' to Panel';
            
    $this->login_19 "Account Registered - [$ident]"// Subject in E-Mail sent to Admin
            
    $this->login_20 'Registration Information'// Subject in E-Mail sent to User
            
    $this->login_21 "New Account Registered - [$ident]. Please Login to your Administrative Panel at $url_path/$file_login to set the Status of the Account."// Text in E-Mail Body sent to Admin
            
    $this->login_22 "Your $system_name Account - [$ident] has been Created. Your Account is currently Awaiting Approval from the Administrators. Once Approved, you will be Notified via E-Mail.\n\nYou may go to $url_path/$file_index?id=$ident to view your Status."// Text in E-Mail Body sent to User
            
    $this->login_23 'Account has been Created Successfully. Please Check your E-mail for more Information.';

        }

    }

    ?>
    Her'es how it basically works.
    Script checks for cookie in the user's system. If no cookie is found, it'll assign a default language, which would be english.
    If $setLang is defined, it'll check first if the language requested exist in the specified directory. If it does, it'll include the language file. It it doens't exist, it'll show an error message that the requested language file was invalid. it'll then assign the default language (english) to the user.

    When assigning the cookie, the script will check if there's a 'www' in front of the host name. basically, its for supporting netscape browsers.

    Cookies assigned will remain active for 1 year.
    Personally, I feel that using classes for languages is better then including a file with all the variables for each text. This gives you more room for variable names and reduce variable conflicting to a minimal.

    Hope it helps.
    "Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
    -- Albert Einstein


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
  •