Nov 22, 2009

Multilingual Site: Send The User To Page Of Choice

free web hosting
Open Discussion & Free Web Hosting > Computers & Tech > Programming > Scripting > PHP

Multilingual Site: Send The User To Page Of Choice

Alexandre Cisneiros
If you have one site in diferent laanguages, this simple script can redirect the user to the correct page acording to his/her language:

CODE


<?php
// Enslish EUA
elseif ($HTTP_ACCEPT_LANGUAGE == "en-us"){
header("Location: index_eng.html");
}

// Inglês UK
elseif ($HTTP_ACCEPT_LANGUAGE == "en-gb"){
header("Location: ingles_enuk.html");
}

// Portuguese [Brazil]
if ($HTTP_ACCEPT_LANGUAGE == "pt-br"){
header("Location: index_ptbr.html");
}

//German
elseif ($HTTP_ACCEPT_LANGUAGE == "de-de"){
header("Location: index_ger.html");
}

// Swedish
elseif ($HTTP_ACCEPT_LANGUAGE == "sv-se"){
header("Location: index_swe.html");
}

// French
elseif ($HTTP_ACCEPT_LANGUAGE == "fr-fr"){
header("Location: index_fre.html");
}

// Chinese
elseif ($HTTP_ACCEPT_LANGUAGE == "zh-cn"){
header("Location: index_chi.html");
}

// Thai
elseif ($HTTP_ACCEPT_LANGUAGE == "th-th"){
header("Location: index_tha.html");
}

?>



-----This is not a full tutorial, but just a little code snippet. Moved from [Tutorials > Programming > PHP] to [Programming > Scripting > PHP]-----szupie

Now i saw that EDIT is disabled, so this is a correction:

CODE
CHANGE THE FIRSTS 3 IF's to this:
///////////////////////////////////////////////////////
<?php
// Enslish EUA
if ($HTTP_ACCEPT_LANGUAGE == "en-us"){
header("Location: index_eng.html");
}

// Inglês UK
elseif ($HTTP_ACCEPT_LANGUAGE == "en-gb"){
header("Location: ingles_enuk.html");
}

// Portuguese [Brazil]
elseif ($HTTP_ACCEPT_LANGUAGE == "pt-br"){
header("Location: index_ptbr.html");
}
////////////////////////////////////////////////////////
THE REST IS OK.

 

 

 


Comment/Reply (w/o sign-up)

Quatrux
What about if I do not want to go to my browser set language ? and have you seen what kind of ACCEPT LANGUAGE most of the browsers send ? I usually set a lot, like, how would your script work with this ?

"en,lt;q=0.9,ru;q=0.8,de;q=0.7" ?

And using header is the last thing in this kind of type of script I would use. wink.gif

Comment/Reply (w/o sign-up)

Houdini
Instead of using a bunch of elseif statements why not a CASE in a switch or even better, why not just have a drop down box or graphics that allow a user to choose the language themselves? The reason you should not attempt to send some one to a particular language would be that they are on a computer that might not be their own and possibly if they are in another country while using that computer. On my sites you have 33 Flags representing 33 various languages that the user selects when coming to the site, and in my forums they can choose from 20 languages including English with two forms of Chinese and two forms of German. There they must of course choose the language themselves, but of course this is only if they are members since the only way to change your profile is to be a member.

Comment/Reply (w/o sign-up)

Alexandre Cisneiros
QUOTE(Houdini @ Jan 30 2006, 09:16 PM)
Instead of using a bunch of elseif statements why not a CASE in a switch or even better, why not just have a drop down box or graphics that allow a user to choose the language themselves?

Ok. Here is it:
CODE

switch ($HTTP_ACCEPT_LANGUAGE) {
case "en-us": header("Location: index_eng.html");
break;
case "en-uk": header("Location: index_enuk.html");
break;
case "pt-br": header("Location: index_ptbr.html");
break;
}

// ETC......


QUOTE
The reason you should not attempt to send some one to a particular language would be that they are on a computer that might not be their own and possibly if they are in another country while using that computer. On my sites you have 33 Flags representing 33 various languages that the user selects when coming to the site, and in my forums they can choose from 20 languages including English with two forms of Chinese and two forms of German. There they must of course choose the language themselves, but of course this is only if they are members since the only way to change your profile is to be a member.
[*


You can add it on the site. Example:
QUOTE
AFTER REDIRECT, YOU CAN OUT THIS ON EACH PAGE:
//////////////////////////////////
Choose your language: [ box with langueages] [ Ok button]

 

 

 


Comment/Reply (w/o sign-up)

CrazyPensil
Actually, the way of redirect is quite a silly and takes a lot of place on the server.

to put that select box, when user gives his value,

CODE
<?php
   $lang=array(
           'ru_text1' => 'Âûïîëíåííàÿ êîìàíäà',
           'ru_text2' => 'Âûïîëíåíèå êîìàíä íà ñåðâåðå',
           'ru_text3' => 'Âûïîëíèòü êîìàíäó',
           'ru_text4' => 'Ðàáî÷àÿ äèðåêòîðèÿ',
           'ru_text5' => 'Çàãðóçêà ôàéëîâ íà ñåðâåð',
           'ru_text6' => 'Ëîêàëüíûé ôàéë',
           'ru_text7' => 'Àëèàñû',
           'ru_text8' => 'Âûáåðèòå àëèàñ',
           'ru_butt1' => 'Âûïîëíèòü',
           'ru_butt2' => 'Çàãðóçèòü',
           'ru_text9' => 'Îòêðûòèå ïîðòà è ïðèâÿçêà åãî ê /bin/bash',
           'ru_text10' => 'Îòêðûòü ïîðò',
           'ru_text11' => 'Ïàðîëü äëÿ äîñòóïà',
           'ru_butt3' => 'Îòêðûòü',

           'eng_text1' => 'Executed command',
           'eng_text2' => 'Execute command on server',
           'eng_text3' => '&nbsp;Run command',
           'eng_text4' => 'Work directory',
           'eng_text5' => 'Upload files on server',
           'eng_text6' => 'Local file',
           'eng_text7' => 'Aliases',
           'eng_text8' => 'Select alias',
           'eng_butt1' => 'Execute',
           'eng_butt2' => 'Upload',
           'eng_text9' => 'Bind port to /bin/bash',
           'eng_text10' => 'Port',
           'eng_text11' => 'Password for access',
           'eng_butt3' => 'Bind'
           );
//etc
//$language is choice of the user
   print "$$language_text1;
//etc
?>


And print it when needed.

Comment/Reply (w/o sign-up)

mastercomputers
Why not just listen to W3C Standards for the correct method of doing this without any dynamic scripting involved. It makes sense considering there's tonnes of languages, that to write a line of code for each one, does not make any sense. If you develop alternative pages in different languages then I suggest you read W3C on how it should be handled and not rely on what device connects to you, because it's possible they don't have an ACCEPT_LANGUAGE and you have not set a default for if it doesn't match. Also what someone said with the ACCEPT_LANGUAGE having a mixed string, since you can have it set up by preference, including the language that you prefer, but if you're not checking for their preferred language and only one that they've set, then you're definitely better off using W3C's way.

$HTTP_ vars are old, learn what's now and not in the past, no point in continuing with something deprecated.

The new variable is $_SERVER['HTTP_ACCEPT_LANGUAGE'];


Cheers,


MC

Comment/Reply (w/o sign-up)

TavoxPeru
Hi, one of my clients need to translate his website to english -is in spanish- because he wants to capture more clients, so after investigating and testing different solutions i find that the simplest way to do this is by using a session variable that holds the default/user language, some files for each translation and the use of associative arrays.

If someone wants to see this in action go to: Refugio de Santiago - New, is not finished yet and any comments or sugestions are welcome.

BTW i dont try the W3C standards, i gonna see later.

best regards,

Comment/Reply (w/o sign-up)


Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Multilingual Site User Choice

  1. Php Script To Download File From Another Site - (11)
    hi i need a php or java script code for downloading files from other sites to my site for example:
    http://download.com/file.zip to http://mysite.com/file.zip thanks...
  2. How To Create/edit/delete Ftp Accounts With Php - Help me to create one php page to create FTP user accounts in Unix Ser (2)
  3. How To Reset The Server Variable Php_auth_user - (9)
    Hi, i'm developing a web application which obviously requires a log in/log out script that i
    just implementing but i dont know why the log out script dont work fine. The problem is related
    with the server variable $_SERVER which remains set even when in the log out script i unset it with
    the unset() function. Does someone knows how can i reset or clear the server variable $_SERVER ???
    Best regards, ...
  4. Make A Script Run Even If No User Is Online - (6)
    Hey! Is there any way to make a script run, even if no user is online. Because at the moment, my
    scripts run, only when a user is online. And another thing: How can i make the following: (this is
    just an example) mysql_query"SELECT maxhp FROM users WHERE username = 'allusers'"; How can I
    select all users maxhp, in the same query? Thanks //Feelay...
  5. User Authentication Session Handling Problems - Authorization server variables not staying across pages (14)
    This is quite a bit of problem I am facing, and I cannot point exactly where I am going wrong. I
    have been lurking around here at the Asta Host forums with regard to login and user authentication
    scripts and I have got as far as this: - Starting a session - Registering a session variable -
    Using the variable to check if the user is authenticated or not. - Authenticating the user through
    MySQL database - Logging of the user, by setting the session variable to un-authenticated I have
    been able to achive the following things too that I think is not related to this proble...
  6. How Do U Make Members Only Web-site - (7)
    how do u make it that only a member of that site can view that page?...
  7. Automated Product Suggestion Script - Compare user lists and suggest related items based on pattern matching (2)
    I recently got an idea for a project and one of the features I wanted the project to have was an
    automated suggestion service. If anyone has been to Amazon, it would work much like their
    recommended product feature. What I want to do is take several users lists of whatever but for this
    example, I'll use web links like from the browser history. I would want to suggest links to a
    user based on common links in many other users lists. User A: Amazon, Ebay, Excite, Google, Yahoo,
    MySpace, Walmart User B: Amazon, Ebay, Google, Yahoo, You Tube, MySpace, CVS User C: Amazo...
  8. Proper Way To Grab User Data? - (1)
    I'm working on a script where there is a custom user profile and I was wondering if there was a
    more efficient way to grab data stored in a database than this method: CODE $sql = "SELECT *
    FROM users WHERE `access_name` = \""  .$active_user. "\""; $row =
    mysql_fetch_array(mysql_query($sql)); //Link the two tables together; grab the most common thing
    that is the *SAME* $user_id = $row ; $sql2 = "SELECT * FROM content WHERE `cid` = \""  .$user_id.
    "\""; $row2 = mysql_fetch_array(mysql_query($sql2)); Then on the pages, I just do a where ever
    something is supp...
  9. Backing Up User Forms As Static HTML - (5)
    System: Activity System for use in Universities Users: Faculty members Scenario: User fills out a
    list of activites they participated in. Example: A faculty member attended a seminar about Object
    Orientated Programming. They record that seminar into their records by filling out a form and
    adding that activity into the database and identifying it with a designed term id. Spring terms are
    different than fall terms etc etc. We want to create html snapshots of these forms that can be
    included by a simple include('oldForm.html') into another form for review. ...
  10. Should This Great Site Offer Imagemagick ? - May be the admin of this site think over it. (3)
    Hi As we all know that this website is very good and offering good services. I just wanna know if
    other people also want ImageMagick to be installed on this server with free accounts... so please
    let me know and lets check if the Admin of this site can isntall it..... Fun...
  11. Generating A Table Into A File In CSV Format - and letting user download the file (6)
    I'm working on a project, part of which consists of working with large tables of different
    kinds. Now, I'm using a page seeking technique which allows you to browse through the records
    depending on which page you want to see and how many records you want to see on each page. Now, I
    need a link (or a form button) on each page which, when clicked, will throw a file to the user for
    download (the download window should popup immediatly) which will give the part of the table,
    currently being viewed, in CSV format. One way I can think of to generate the file is manu...
  12. PHP Based Site Access Authentication - Help - How to block parts of your web-site ?? (4)
    How can i program my web page using php that when the value of the login box is equal to some string
    then go to my success.html otherwise on my fail.html????help me guys!
    ------------------------------------ It would help the readers far better to understand what your
    problem is - if you state the nature of it in short in your topic title, instead of just "Php help".
    It'll also get you a lot more responses. Am changing your topic title to give you an example.
    All the best /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /> m^e...
  13. Dynamic Site Design - Where Do I Start ? - (7)
    I am new to php. I have some programing background in html, javascript, and c++ but have never done
    anything in php Can someone reccomend some good sites or books etc that can help someone who is
    completely new? My ultimate goal is to make a game like/similar to ponyisland.net...
  14. Need Help Is Adding A PHP Based News Module To My Site - (2)
    Hey guys i need a simple help i'm builing a homesite and i have a little spot for news. Well i
    just place there the Topics and add a link to another page "news.php". Well its obvious that i dont
    want to build a file for each news that i have so i know that exists a way to work with SQL & PHP. I
    will show want i'm doing CODE        require ('mysql.php');       
    $query="SELECT * FROM News ORDER BY `data` ASC LIMIT 0,5 ";        $result=mysql_query($query);
               $num=mysql_num_rows($result); mysql_close(); echo " Outras Other News "; $i=...
  15. Using Bitflags To Restrict Site/page Permissions - (1)
    My professor is designing a website that uses bit-flag checking to allow access to certain pages.
    You login, validate login, and store their allowed bit flag into a session variable. Then you
    compare to see if they have access or not. It's fairly new to me, but it's apparently very
    common with linux users. Sounds interesting to me, just wondering if any one has used this, or is
    it a little too much for simple pages. His site however is going to be more of "software" for
    several users. Is it very secure and does it work well?...
  16. How To Use Cookie In Your Web Site ? - this semple code to use and get cookie (1)
    what is the cookie ? the cookis it is some info sent and save in user computer whare i can use the
    cookies? becouse the cookies it like the header you can not send it after any output wes sent so
    you must send the cookies before any output like as ,echo and any other code i well make an E.X.
    to use the cookies you must have 2 file index.php update.php ---------- in the index.php add this
    code CODE    // This section must go at the top of the page that will display    // the
    users favorites.  These are the 'default' URLs that the user    // will se...
  17. Do You Want A Mail Form In Your Site - (2)
    Notice from m^e: Repeat post. Credits reduced by 5 days. Learn to USE
    THE SEARCH BUTTON before you make such posts. did you want to have in your web site mail form
    that allow the user to send mails to anther mail from his mail e.g. the compose in yahoo CODE
    from to cc bcc subject
    function param($Name)         {         global
    $HTTP_POST_VARS;         if(isset($HTTP_POST_VARS ))            return($H...
  18. Site Counters - Help Needed - (13)
    I want a good Site counter(to keep track of visitors) for my site..... can nebody temme.....
    where will i get free stuff on this... (dont ask me to google..and try out..i am doing that..just in
    case u know someplace) OR Can how do i design my own (which seems quite....difficult for me) Plz
    help!! Satya...
  19. Own Links On Site - (6)
    I'm thinking of having some kind of system so the users can register and then put up their
    links. Everything should be saved in some kind of database. Anyone now any tutorial or guide or
    something like that of how to do that?...
  20. User Ip And City Tracing In Php - User IP and City Tracing in PHP (3)
    Hi, Am in damm need of tracing the Users IP and City hwre they are from with PHP, Any help
    please....... Thanks in Advance Arunkumar.H.G...



Looking for multilingual, site, send, user, page, choice

See Also,

*SIMILAR VIDEOS*
Searching Video's for multilingual, site, send, user, page, choice
advertisement



Multilingual Site: Send The User To Page Of Choice

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com