Page 1 of 1

php multilanguage site..code missing please help

Posted: Wed Sep 23, 2009 2:01 pm
by tinoda
I have 2 folders(english & german) with complete translated text, etc. I need to create the website in such a way that if a user clicks on their preferred language even if they r deep within the page, the translation will simply translate that current page and not take the user to the start page of their preferred language like what I currently have. Yesterday somebody gave me a clue with 4 points which are:
1. Check if the "change Language" option was POSTED.
2. If yes, then get the current URL
3. Modify the current URL to the other language equivalent
4. Do a header redirect to the new URL

following that I came up with the following codes and I am stuck on number 3 which I need help on.

Code: Select all

1. CHECK IF THE "change Language" OPTION WAS POSTED.
<a href="index.html?lang=en"><img src="images/en.png" /></a>
<a href="index.html?lang=de"><img src="images/de.png" /></a>
 
2. IF YES, THEN GET THE CURRENT URL
<?php
function curPageURL() {
 $pageURL = 'http';
 if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
 $pageURL .= "://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
 }
 return $pageURL;
}
?>
 
3. MODIFY THE CURRENT URL TO THE OTHER LANGUAGE EQUIVALENT
I am stuck here.  please help me how can i modify the currentURL to the other equivalent.  I have hundreds of pages and i am clueless really.
 
4. Do a header redirect to the new URL
<?php
header("Location: http://mygerman site/");
exit();
?>
i could hv easily done this with mysql but i cant becoz of circumstances beyond my control. thank you for helping me.

Re: php multilanguage site..code missing please help

Posted: Wed Sep 23, 2009 11:41 pm
by Robert07
It would help if you give an example of a URL you would be looking at when you want to switch languages. Also please mention what both of the top level folder names are (for each language). Then I could give you a couple lines of code to switch from one to the other.

Re: php multilanguage site..code missing please help

Posted: Wed Sep 23, 2009 11:51 pm
by Ollie Saunders
Something like this?:

Code: Select all

function curPageURL() {
    $pageURL = 'http';
    if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
    $pageURL .= "://";
    $pageURL .= $_SERVER["SERVER_NAME"] . '/';
    # Alter the value of $_GET beforehand to change the URL.
    $GETParams = array();
    foreach ($_GET as $k => $v) { $GETParams[] = urlencode($k) . '=' . urlencode($v); }
    return $pageURL . implode('&', $GETParams);
}