+ Reply to Thread
Results 1 to 9 of 9

Thread: PHP Muilti-Language script

  1. #1
    sarvar's Avatar
    sarvar is offline x10Hosting Member sarvar is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    82

    PHP Muilti-Language script

    Hey, I recently made a php script on my site which allows visitors to change the language. I made languages folder and stored en.php, ru.php and uz.php with translations. Then I pulled the language file with this code.

    PHP Code:
    // Get user language  
    $lang $_GET['lang'];    
      
    switch(
    $lang){  
          
         case 
    'en':  
                include 
    'languages/en.php';  
                break;  
         case 
    'ru':  
                include 
    'languages/ru.php';  
                break;  
         case 
    'uz':  
                include 
    'languages/uz.php';  
                break;  
         default:  
            include 
    'languages/en.php';              
                    

    When I visit the site, default language works fine. But when I assing lang in the URL, I get random letters. Any ideas to fix this issue?
    CLICK HERE to Thank Me.
    (You must be logged in into forums.)

  2. #2
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: PHP Muilti-Language script

    are you using the proper encoding? try utf-8, as it seems to work the best. if that doesn't work for your current language, take a look at the iso ones.

    also, a link to the site would help us out ;)

  3. #3
    sarvar's Avatar
    sarvar is offline x10Hosting Member sarvar is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    82

    Re: PHP Muilti-Language script

    I don't know what you mean by utf-8.

    See the problem yourself.

    ENGLISH VERSION and DEFAULT LANGUAGE

    Also, If I change the default langiage to english, It works fine, but when I set the language from URL it gets all nasty.

    (I think cossacks is down right now.)
    Last edited by sarvar; 01-17-2009 at 12:40 PM.
    CLICK HERE to Thank Me.
    (You must be logged in into forums.)

  4. #4
    xPlozion's Avatar
    xPlozion is offline x10 Elder xPlozion is an unknown quantity at this point
    Join Date
    Mar 2008
    Location
    Delaware, USA
    Posts
    872

    Re: PHP Muilti-Language script

    appears to be a problem with how you implement your lang file.
    can you post a snippet of the lang file (pref en)?

    also, i'm using a custom multi-dimensional lang file on one of my projects, and there's no problems with it, so if it needs to be rewritten, i can help ;)
    Last edited by xPlozion; 01-17-2009 at 03:04 PM.

  5. #5
    sarvar's Avatar
    sarvar is offline x10Hosting Member sarvar is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    82

    Re: PHP Muilti-Language script

    Ok, here is a snippet code from language file and php file.

    PHP Code:
    <?php

    // Top Menu
    $lang['HOME'] = "Home";
    $lang['MP3'] = "Mp3";
    $lang['CONTACT'] = "Contact";

    // Login Section
    $lang['LOGIN'] = "Login";
    $lang['LOGOUT'] = "Logout";
    $lang['USERNAME'] = "Username";
    $lang['PASSWORD'] = "Password";
    $lang['VERIFY_PASSWORD'] = "Verify Password";
    $lang['REMEMBER'] = "Remember";
    $lang['DONT_HAVE_ACCOUNT'] = "Don\'t have account?";
    $lang['MY_ACCOUNT'] = "My Account";
    $lang['WELCOME'] = "Welcome";
    $lang['EMAIL'] = "Email";
    $lang['FIRST_NAME'] = "First Name";
    $lang['LAST_NAME'] = "Last Name";
    $lang['GENDER'] = "Gender";
    $lang['MALE'] = "Male";
    $lang['FEMALE'] = "Female";
    $lang['BIRTHDATE'] = "Birth Date";
    $lang['COUNTRY'] = "Country";
    $lang['ENTER_CAPTCHA'] = "Enter the code above";
    $lang['REGISTER'] = "Register";

    // Months
    $lang['JANUARY'] = "January";
    $lang['FEBRUARY'] = "February";
    $lang['MARCH'] = "March";
    $lang['APRIL'] = "April";
    $lang['MAY'] = "May";
    $lang['JUNE'] = "June";
    $lang['JULY'] = "July";
    $lang['AUGUST'] = "August";
    $lang['SEPTEMBER'] = "September";
    $lang['OCTOBER'] = "October";
    $lang['NOVEMBER'] = "November";
    $lang['DECEMBER'] = "December";

    // Admin Section
    $lang['ADMIN_HOME'] = "Administrator";

    // Error messages
    $lang['RESTRICTED'] = "Restricted!";
    $lang['BANNED'] = "Sorry, you appear to be banned from our site. Here's why you got banned:<br />".$get_banned_ip_rst."<br />Feel free to contact us <a href=\"contact.php\">here</a>.";
    $lang['NULL_USERNAME'] = "Error: You must enter your username.";
    $lang['NULL_PASSWORD'] = "Error: You must enter your password.";
    $lang['BAD_LOGIN'] = "Error: Please verify your username and password.";
    $lang['REG_NULL_LOGIN'] = "ERROR: Please enter username you would like to use.";
    $lang['NULL_EMAIL'] = "ERROR: Please enter your e-mail.";
    $lang['NULL_SEARCH'] = "You did not enter a search term.";
    $lang['CHAR_SEARCH'] = "Query must be at least 3 characters long.";
    $lang['INVALID_SEARCH_LETTER'] = "No singers exist for that letter.";

    // Misc
    $lang['SEARCH'] = "Search";
    $lang['SEARCH_RESULTS'] = "Search Results for";
    $lang['INVALID_SEARCH'] = "No matches found for";
    $lang['RE_SEARCH'] = "Search Again!";

    ?>
    PHP file

    PHP Code:
    <?php
    // Top panel
    $top_menu "<ul>
                  <li><a href=\"../index.php\">"
    .$lang['HOME']."</a></li>
                  <li><a href=\"../contact.php\">"
    .$lang['CONTACT']."</a></li>
                </ul>"
    ;
    ?>
    CLICK HERE to Thank Me.
    (You must be logged in into forums.)

  6. #6
    woiwky is offline x10 Lieutenant woiwky is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    390

    Re: PHP Muilti-Language script

    You're setting $lang to $_GET['lang'], and then when the language file is included you're using the same variable name for the string array. The string keys equate to a numeric 0, and the first letter of each string is being placed as the first letter of $lang. That is, those "random" characters are actually the first letter of $lang['RE_SEARCH'].

    In short, don't bother storing $_GET['lang'] in a variable, just use it in the switch statement instead ;-)
    "But you have access to the greatest source of knowledge in the universe."
    "Well I do talk to myself sometimes, yes."

    "I'm back, and I'm bad! Obviously within certain, sensible, preset parameters"

  7. #7
    sarvar's Avatar
    sarvar is offline x10Hosting Member sarvar is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    82

    Re: PHP Muilti-Language script

    Thank you woiwky! Your answer fixed the problem. +reps.
    CLICK HERE to Thank Me.
    (You must be logged in into forums.)

  8. #8
    scriptando is offline x10Hosting Member scriptando is an unknown quantity at this point
    Join Date
    Mar 2008
    Posts
    30

    Re: PHP Muilti-Language script

    Also good for you if there is a prioblema you must put this sentiencia for when not in the url and do not generate error

    if(isset($_GET["xxx"]))
    {
    ...
    }

  9. #9
    sarvar's Avatar
    sarvar is offline x10Hosting Member sarvar is an unknown quantity at this point
    Join Date
    Sep 2007
    Posts
    82

    Re: PHP Muilti-Language script

    I have done that, that was just a code that was making error. Thanks though.
    CLICK HERE to Thank Me.
    (You must be logged in into forums.)

+ Reply to Thread

Similar Threads

  1. Photo-Graffix Gallery Php Script...
    By millart in forum Free Hosting
    Replies: 7
    Last Post: 09-17-2008, 11:42 AM
  2. foward mail to a php script
    By ruicos in forum Programming Help
    Replies: 3
    Last Post: 09-13-2008, 07:55 AM
  3. Cannot get php script to work
    By avidgamer in forum Free Hosting
    Replies: 3
    Last Post: 09-03-2008, 04:35 PM
  4. Replies: 3
    Last Post: 03-10-2008, 12:22 PM
  5. Unstand PHP?
    By o0slowpaul0o in forum Tutorials
    Replies: 8
    Last Post: 01-07-2008, 09:16 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
x10hosting free hosting for the masses
dedicated servers